Referencing Public Variables

J

Joe Delphi

Hi,

I have two forms in my MS Access program. In one of the forms I
have a public variable declared in the declaration section

Form1:

Public strTest As String

Option Compare Database
-------------------------------------



In Form 2, I attempt to reference that variable like this:

Variable2 = Form1.strTest

also tried: Variable2 = Form1!strTest but that didn't work
either.

But I get an error message which says "Object required" when my
code is executing in Form 2. There is no Option Explicit setting in Form 2.

How should I reference the public variable in Form 2 so that I do
not get an error message?


JD
 
G

Graham R Seach

Joe,

Refer to it in either of the following ways:
Form_Form1.strTest
....or...
Forms!Form1.strTest

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
P

(PeteCresswell)

Per Graham R Seach:
Form_Form1.strTest
...or...
Forms!Form1.strTest

Could somebody comment on when one or another of those syntaxes is more/less
desirable?
 
G

Graham R Seach

Pete,

Well, since no-one else seems to be interested in responding to your
question...
Form_Form1.strTest references the variable through the form class,
whereas Forms!Form1.strTest references it through the Forms collection.
Either is fine.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 

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