![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
When opening a form there appears to me to be two ways to do so: Option 1: docmd.openform "Form1" Option 2: dim frm as Form set frm = New Form1 OK so my question is: Can I combine the two options? dim frm as Form docmd.OpenForm strFormName set frm = Forms(Forms.Count-1) 'the newest form created The reason I don't think I can is because when I use option1 I can click design view on the form but when I use option 2 design view is disabled. I want to combine the two options because using option 1 I can open a form via a string whereas using option 2 I have to specify which form I want to create an instance of. |
#3
| |||
| |||
|
|
and there is no guarantee that Forms(Forms.Count-1) |
#4
| |||
| |||
|
|
Thanks for the corrections I was sloppy with the notation. and there is no guarantee that Forms(Forms.Count-1) I didn't know that. That gives me something to test, because I might need to search through the collection for the right form. The reason is that my collection of forms is not the same form. Depending on what is clicked one of several forms will open and get stored in the collection. This has led me to create a select case statement based upon a string. select strFormName case "A": set frm = new Form_Form1 case "B": set frm = new Form_Form2 'add to the collection to preserve it However this means updating the case statement with every new form I wish to create. I was hoping to avoid the select case statement by opening the form using the docmd.openform statement and pass the strFormName to that then point to it then add it to the collection. |
#5
| |||
| |||
|
|
Thanks for the corrections I was sloppy with the notation. and there is no guarantee that Forms(Forms.Count-1) I didn't know that. That gives me something to test, because I might need to search through the collection for the right form. The reason is that my collection of forms is not the same form. Depending on what is clicked one of several forms will open and get stored in the collection. This has led me to create a select case statement based upon a string. select strFormName case "A": set frm = new Form_Form1 case "B": set frm = new Form_Form2 'add to the collection to preserve it However this means updating the case statement with every new form I wish to create. I was hoping to avoid the select case statement by opening the form using the docmd.openform statement and pass the strFormName to that then point to it then add it to the collection. |
#6
| ||||
| ||||
|
|
Mat, if you don't need to have multiple instances of a form open, why do you need your own collection? |
|
Access maintains a collection of open forms. It's called Forms. You can locate a form if you know its name with: Forms(strFormName) |
|
I never heard of a way to create a class instance without using the literal class name with New |
|
think it would be easier to have a separate procedure with its own collection for each form with multiple instances. OTOH, its your code and if you prefer combining all of them in a single collection, who am I to object. Either way, I believe you will need to add/modify some code for each form. |
#7
| |||
| |||
|
|
Mat, if you don't need to have multiple instances of a form open, why do you need your own collection? My situation is multiple instances of multiple forms. In fact I decided to open every form as an instance of that form. It is probably pushing access to far? Access maintains a collection of open forms. It's called Forms. You can locate a form if you know its name with: Forms(strFormName) My understanding is that one should create and use their own collection when working with instances of a form. When you create a form in a procedure it gets added to the Forms collection for that temporary time and removed when it goes out of scope so you pass the instance of the form to a collection to keep it. I never heard of a way to create a class instance without using the literal class name with New It is a bit irritating there isn't a function, that you can pass a parameter to, to open a form. think it would be easier to have a separate procedure with its own collection for each form with multiple instances. OTOH, its your code and if you prefer combining all of them in a single collection, who am I to object. Either way, I believe you will need to add/modify some code for each form. I was kind of experimenting. Either solution has the same core problem of when you create a new form you have to create new code to manage it. Thanks for the replies to date. They are much appreciated. |
#8
| |||
| |||
|
|
Okay: if you are working with multiple instances, then the Forms collection is not adequate for distinguishing between them, so you do need your own collection. The need for multiple instances is pretty rare. Very few of my production databases use them, so I wouldn't consider it an ideal way to handle forms in general. Further, my experiments with multiple instances of reports has not been too productive, so I don't use that at all. It would be handy if we could use a variable name with the New keywords for the Form_Form1 thingy, but I never followed that through either. |
#9
| |||
| |||
|
|
Thanks for the corrections I was sloppy with the notation. and there is no guarantee that Forms(Forms.Count-1) I didn't know that. That gives me something to test, because I might need to search through the collection for the right form. The reason is that my collection of forms is not the same form. Depending on what is clicked one of several forms will open and get stored in the collection. This has led me to create a select case statement based upon a string. select strFormName case "A": *set frm = new Form_Form1 case "B": set frm = new Form_Form2 'add to the collection to preserve it However this means updating the case statement with every new form I wish to create. I was hoping to avoid the select case statement by opening the form using the docmd.openform statement and pass the strFormName to that then point to it then add it to the collection. |
#10
| |||
| |||
|
|
Hi Mat, I have been puzzling on your problem for som time to try to understand what you are aiming for. I think I miss some point, because I can not translate it to some practical situation that I use. Why you want or need instances of a form, while you can open a form with DoCmd.OpenForm? HBInc. |
![]() |
| Thread Tools | |
| Display Modes | |
| |