Getting error passing variable

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

Good morning, and thanks for reading this.
I have a main form with a subform on it.What I'm trying to do is to pass a
string {strHeader} from the main form to a label on the subform. This is the
code I have.

strHeader = "Delete Staff"

Forms!SubFrmFind!Label6.Caption = strHeader

I keep getting an error when I try to access the subform. It says that Access
can't find the form SubFrmFind referred to in macro or vb code.

I put a msgbox strHeader on the subform and it displays it when both form
load.

Your help is appreciated.
I'm using Access 2003
 
M

Marshall Barton

Afrosheen said:
Good morning, and thanks for reading this.
I have a main form with a subform on it.What I'm trying to do is to pass a
string {strHeader} from the main form to a label on the subform. This is the
code I have.

strHeader = "Delete Staff"

Forms!SubFrmFind!Label6.Caption = strHeader

I keep getting an error when I try to access the subform. It says that Access
can't find the form SubFrmFind referred to in macro or vb code.

I put a msgbox strHeader on the subform and it displays it when both form
load.

Subform is not members of the Forms collection. They are
displayed by a subform control on the mainform. That means
you need to reference the things on a subform by foing
throuught the main form and the subform control. To
reference a subform from a different mainform:
Forms!mainform.subformcontrol.Form.control

Or, a subform from the same main form:
Me.subformcontrol.Form.control

In your case, I think you should use:
Me.SubFrmFind.Form!Label6.Caption = strHeader
 
A

Afrosheen via AccessMonster.com

Thanks Marshall for coming back.
I applied your code and it work just fine.

Thanks for the help.

Marshall said:
Good morning, and thanks for reading this.
I have a main form with a subform on it.What I'm trying to do is to pass a
[quoted text clipped - 10 lines]
I put a msgbox strHeader on the subform and it displays it when both form
load.

Subform is not members of the Forms collection. They are
displayed by a subform control on the mainform. That means
you need to reference the things on a subform by foing
throuught the main form and the subform control. To
reference a subform from a different mainform:
Forms!mainform.subformcontrol.Form.control

Or, a subform from the same main form:
Me.subformcontrol.Form.control

In your case, I think you should use:
Me.SubFrmFind.Form!Label6.Caption = strHeader
 

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