Can I pass OpenArgs to multiple instances of the same form?

  • Thread starter Thread starter Max Moor
  • Start date Start date
M

Max Moor

Hi All,

I've got a form I want to open multiple copies of. It will have a
subform like a checkbook register that displays different accounts' entries
from a general ledger. For example, the general ledger may have entries for
two accounts: Bank1 and Bank2. I want to be able to open a Bank1 register
form and a Bank2 register form at the same time, using the same base form.

I've been reading up on how to manage multiple instances of a form.
Allen Browne has a nice write up using a collection and the hWnd value to
keep track of the various instances.

Is there a way to pass OpenArgs when instanciating a form with the New
keyword?

If not, I considered opening each form hidden, then calling some public
interface function that I could pass the filter info to. That function would
finish the forms setup and make it visible. Is there a better method than
this that is safer or better practice?

Thanks & Regards,
Max
 
As you found, using the New keyword to open a form does not give you the
option of OpenArgs, so you will be looking for alternate approaches.

Calling a generic function in Form_Open or Form_Load sounds fine. If you
need the value after those events, perhaps you could use a hidden unbound
text box.
 
On Tue, 04 Nov 2008 15:46:15 -0800, Max Moor

One option is to give the form a public property (perhaps named
FakeOpenArgs), and then call this property after opening the form.
Unfortunately unlike the real OpenArgs you cannot inspect this value
in the Form_Open event.

Personally I would probably use a hidden control.

-Tom.
Microsoft Access MVP
 
As you found, using the New keyword to open a form does not give you the
option of OpenArgs, so you will be looking for alternate approaches.

Calling a generic function in Form_Open or Form_Load sounds fine. If you
need the value after those events, perhaps you could use a hidden unbound
text box.

Hi Allen,

Thanks for the response. I have a "LeftNav" form that is always open
(uncloseable by user) that does management of the other forms. I'll keep the
collection and call from the Form_Open calls in there. It's not perfect
encapsulation, but it follows a structure, at least.

Thanks again for the good help.

Regards,
Max
 
On Tue, 04 Nov 2008 15:46:15 -0800, Max Moor

One option is to give the form a public property (perhaps named
FakeOpenArgs), and then call this property after opening the form.
Unfortunately unlike the real OpenArgs you cannot inspect this value
in the Form_Open event.

Personally I would probably use a hidden control.

-Tom.
Microsoft Access MVP


Hi Tom,

Thanks for the response. I think I'll end up calling a function from
each new form's Form_Open event. I'm not sure about keeping things around.
Here comes a follow up post. (It's always something with me. :-)

Regards,
Max
 
HI Max,
I had the same problem and since I need multiple instances of various forms
I ended up doing this:
1. created a custom procedure call CustOpenForm and replaced my
docmd.OpenForm(...) with CustOpenForm(...). This should have the same
parameters as the OpenForm, in exactly the same order, to make it easy to
change your existing code.
2. in this procedure, I either create an instance of the form or I'm doing a
plain OpenForm, depends on the form
3. in a module I define a public variable called InstanceOpenArgs as String
4. for each form I want to open as instance I do the following
a. I define a global variable in the form called MyOpenArgs
b. in the Form_Load of the form I put MyOpenArgs=InstanceOpenArgs
c. in the form module, wherever I use Me.OpenArgs I change to MyOpenArgs
5. in the CustOpenForm, when I'm opening an instance
a. I initialize the public variable InstanceOpenArgs with the OpenArgs
parameter of my CustOpenForm procedure
b. I open the instance with the normal set f=new Form_.... this
triggers the Form_Load which then takes the InstanceOpenArgs and uses it
inside the code.

That's it. Not easy but it's the most elegant way I found.

Cheers!
Florin
 
Back
Top