Shorten Forms!Myform! to frm.

J

John J.

From a form I need to to reference to different fields in another form. In
stead of referencing every object like:

strMyString = Forms!Myform!MyField

I would like to use a form variable so that I can shorten my code like:

set frm = "Myform"
strMyString = frm.MyField
strMyString = frm.MyField2

etc.

I tried many syntaxes but I can't get it to work.
Can someone help me out?
Thanks, John
 
J

Jeanette Cunningham

Hi John,
you can use With

With Forms!MyField
strMyString = !MyField1
strMyString2 = !MyField2
End With


If you wish to use frm then you must create a variable for it.

Dim frm As Form

Set frm = Forms!Myform!MyField

With frm
strMyString = .MyField1
strMyString2 = .MyField2
End With

Set frm = Nothing

The above is untested air code, but gives the idea of how to do this.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

John J.

Great! Thanks.

Jeanette Cunningham said:
Hi John,
you can use With

With Forms!MyField
strMyString = !MyField1
strMyString2 = !MyField2
End With


If you wish to use frm then you must create a variable for it.

Dim frm As Form

Set frm = Forms!Myform!MyField

With frm
strMyString = .MyField1
strMyString2 = .MyField2
End With

Set frm = Nothing

The above is untested air code, but gives the idea of how to do this.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

John Mishefske

Minor corrections. You did say "air-code".

Jeanette said:
With Forms!MyField
strMyString = !MyField1
strMyString2 = !MyField2
End With

You meant:

With Forms!Myform
strMyString = !MyField1
strMyString2 = !MyField2
End With

If you wish to use frm then you must create a variable for it.

Dim frm As Form

Set frm = Forms!Myform!MyField

You meant:

Set frm = Forms!Myform

Seems the OP realized the typos but new users may not.

--
John Mishefske, Microsoft MVP 2007 - 2009
UtterAccess Editor
Tigeronomy Software
web: http://www.tigeronomy.com
email: sales ~at~ tigeronomy.com
 
J

Jeanette Cunningham

Good catch

Jeanette Cunningham MS Access MVP -- Melbourne Victoria 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