Macro referencing a subform, in a tab, in a parent form

M

Maxwell

Hello all, grateful for some help....

I have a form (FormStudentManagement), with a subform (FormLNKBEDSTD). On
the subform is a control (LNKBEDSTDCategory) which can only be set to two
options ("Private" and "Homestay").

I have a macro attached to a button on the subform which opens a different
form depending on the setting on the control. It all works beautifully when
I open the subform on its own, but the referencing falls down when it is
embedded in the parent form.

A quick google has informed me that referencing rules change when a subform
is involved, and solutions have been put forward to counter this. I have
tried them to no avail. My current macro condition is:

[Forms]![FormStudentManagement].[FormLNKBEDSTD].[Form]![LNKBEDSTDCategory]="Homestay"

Which causes the following error message:
Microsoft Office Access can't find the form '|' referred to in a macro
expression of Visual Basic code.

Now, this subform IS on a tab, but I am assured that that doesn't come into
the equasion. I have tried several permutations of the above to no avail and
would be grateful for an expert opinion.

Best,
Max
 
D

Daryl S

Maxwell -

To reference a control on a subform from a control on the parent form, you
need to reference the subform, then the FORM property of the subform, then
the control on the subform. Try this:

Me.[FormLNKBEDSTD].Form.LNKBEDSTDCategory = "Homestay"

Or from a place other than the main form:

[Forms]![FormStudentManagement].[FormLNKBEDSTD].Form.LNKBEDSTDCategory =
"Homestay"
 
M

Maxwell

Hi Daryl,

Thanks for that, but it still throws up an error. I used the second
formula you suggested but it still comes up and says that it can't find the
form 'FormLNKBEDSTD' referred to in a macro expression.

As I say, I've tried several permutations of the original formula and it
just doesn't like it...

Max

Daryl S said:
Maxwell -

To reference a control on a subform from a control on the parent form, you
need to reference the subform, then the FORM property of the subform, then
the control on the subform. Try this:

Me.[FormLNKBEDSTD].Form.LNKBEDSTDCategory = "Homestay"

Or from a place other than the main form:

[Forms]![FormStudentManagement].[FormLNKBEDSTD].Form.LNKBEDSTDCategory =
"Homestay"


--
Daryl S


Maxwell said:
Hello all, grateful for some help....

I have a form (FormStudentManagement), with a subform (FormLNKBEDSTD). On
the subform is a control (LNKBEDSTDCategory) which can only be set to two
options ("Private" and "Homestay").

I have a macro attached to a button on the subform which opens a different
form depending on the setting on the control. It all works beautifully when
I open the subform on its own, but the referencing falls down when it is
embedded in the parent form.

A quick google has informed me that referencing rules change when a subform
is involved, and solutions have been put forward to counter this. I have
tried them to no avail. My current macro condition is:

[Forms]![FormStudentManagement].[FormLNKBEDSTD].[Form]![LNKBEDSTDCategory]="Homestay"

Which causes the following error message:
Microsoft Office Access can't find the form '|' referred to in a macro
expression of Visual Basic code.

Now, this subform IS on a tab, but I am assured that that doesn't come into
the equasion. I have tried several permutations of the above to no avail and
would be grateful for an expert opinion.

Best,
Max
 
D

Daryl S

Maxwell -

I just re-read your original post. You say the macro is on the subform, I
was thinking it was on the main form. You do not need to specify the current
form (which happens to be the subform since that is where your button is).
Just use this:

LNKBEDSTDCategory = "Homestay"

--
Daryl S


Maxwell said:
Hi Daryl,

Thanks for that, but it still throws up an error. I used the second
formula you suggested but it still comes up and says that it can't find the
form 'FormLNKBEDSTD' referred to in a macro expression.

As I say, I've tried several permutations of the original formula and it
just doesn't like it...

Max

Daryl S said:
Maxwell -

To reference a control on a subform from a control on the parent form, you
need to reference the subform, then the FORM property of the subform, then
the control on the subform. Try this:

Me.[FormLNKBEDSTD].Form.LNKBEDSTDCategory = "Homestay"

Or from a place other than the main form:

[Forms]![FormStudentManagement].[FormLNKBEDSTD].Form.LNKBEDSTDCategory =
"Homestay"


--
Daryl S


Maxwell said:
Hello all, grateful for some help....

I have a form (FormStudentManagement), with a subform (FormLNKBEDSTD). On
the subform is a control (LNKBEDSTDCategory) which can only be set to two
options ("Private" and "Homestay").

I have a macro attached to a button on the subform which opens a different
form depending on the setting on the control. It all works beautifully when
I open the subform on its own, but the referencing falls down when it is
embedded in the parent form.

A quick google has informed me that referencing rules change when a subform
is involved, and solutions have been put forward to counter this. I have
tried them to no avail. My current macro condition is:

[Forms]![FormStudentManagement].[FormLNKBEDSTD].[Form]![LNKBEDSTDCategory]="Homestay"

Which causes the following error message:
Microsoft Office Access can't find the form '|' referred to in a macro
expression of Visual Basic code.

Now, this subform IS on a tab, but I am assured that that doesn't come into
the equasion. I have tried several permutations of the above to no avail and
would be grateful for an expert opinion.

Best,
Max
 

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