Open multiple intances of same form

A

Andrew Tapp

I am able to open a form using the syntax;

DoCmd.OpenForm "frmFormName", acNormal

The main form frmFormName has a subform in it frmsubSubformName. Some code
in this subform refers to a value in a text field in the main form e.g.
Me.Parent!txtFieldName

This works well, with no issues, however this is where it gets interesting.

If i use the following code, in order to open multiple intances of the same
form;

Dim frm as Form
Set frm = New Form_frmFormName

I am unable to refer to the value of the text field in the main form and get
an error 2450 'can't find the form 'frmFormName' referred to in a macro
expression or visual basic code'.

Please advise the syntax for referring to the main form text field from the
subform when opened using 'Set frm = New Form_frmFormName'.

Many thanks.
 
A

Allen Browne

In what event are you trying to refer to the control on the parent form?

The subform may load before the parent form, so if it's one of the early
events (such as Form_Open or Form_Load), you may just need to use error
handling to recover. It should work one the main form has loaded.
 
D

Dirk Goldgar

Andrew Tapp said:
I am able to open a form using the syntax;

DoCmd.OpenForm "frmFormName", acNormal

The main form frmFormName has a subform in it frmsubSubformName. Some
code
in this subform refers to a value in a text field in the main form e.g.
Me.Parent!txtFieldName

This works well, with no issues, however this is where it gets
interesting.

If i use the following code, in order to open multiple intances of the
same
form;

Dim frm as Form
Set frm = New Form_frmFormName

I am unable to refer to the value of the text field in the main form and
get
an error 2450 'can't find the form 'frmFormName' referred to in a macro
expression or visual basic code'.

Please advise the syntax for referring to the main form text field from
the
subform when opened using 'Set frm = New Form_frmFormName'.


Whart version of Access are you using? I just checked this out in Access
2003 with a test form & subform, and the syntax (on the subform)

Me.Parent!ControlName

and

Me.Parent.ControlName

both worked fine.

Are you sure that's the statement that has the problem? It seems much more
likely that you have some other code or expression that is referring to the
parent form by name, rather than by object reference.
 
A

Andrew Tapp

Many thanks for your replies.

Allen; the subform was loading before the main form, and i've changed the
code to reflect this. The main form was calling a sub in the subform on load
of the main form and then populating some total fields on the subform based
on values on the main form. If that makes sense. I'm now passing some
optional paramters to the sub. This works well.

Dirk; It's Access 2000, and yes it is the code further on in, see above.

Everything is now working as it should. Many thanks for your replies.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top