Forms property using varables

S

StuJol

im using access 2003 and have a form "form1" with several command buttons on.
each command button opens the same form "form2" but displaying different
records. when "form2" closes, it updates different feilds on "form1"

for example when form2 closes the following code runs in the close event
Forms!frm_PlantLog_Add.P2602A= "Offline"

i dont want to hard code P2602A, instead i want ti use a varable. i created
a varable in a module 'Public EquipmentTagString As String'

when the command button is pressed on form1 it sets EquipmentTagString as
P2602A which works ok, the problem is using the varable in the forms
property, so ive gone from

Forms!frm_PlantLog_Add.P2602A= "Offline" to
Forms!frm_PlantLog_Add.EquipmentTagString = "Offline"

which doesnt work, ive tried

Forms!frm_PlantLog_Add. & EquipmentTagString = "Offline"

also tried

"Forms!frm_PlantLog_Add." & EquipmentTagString = "Offline"

but dont work. can someone point me in the righht direction to use a varable
in a forms property.
 
S

Stuart McCall

StuJol said:
im using access 2003 and have a form "form1" with several command buttons
on.
each command button opens the same form "form2" but displaying different
records. when "form2" closes, it updates different feilds on "form1"

for example when form2 closes the following code runs in the close event
Forms!frm_PlantLog_Add.P2602A= "Offline"

i dont want to hard code P2602A, instead i want ti use a varable. i
created
a varable in a module 'Public EquipmentTagString As String'

when the command button is pressed on form1 it sets EquipmentTagString as
P2602A which works ok, the problem is using the varable in the forms
property, so ive gone from

Forms!frm_PlantLog_Add.P2602A= "Offline" to
Forms!frm_PlantLog_Add.EquipmentTagString = "Offline"

which doesnt work, ive tried

Forms!frm_PlantLog_Add. & EquipmentTagString = "Offline"

also tried

"Forms!frm_PlantLog_Add." & EquipmentTagString = "Offline"

but dont work. can someone point me in the righht direction to use a
varable
in a forms property.

Forms!frm_PlantLog_Add(EquipmentTagString) = "Offline"

Wherever you would use a bang (!) you can use that alternative syntax. Those
are the two ways to access members of a collection, in this case the form's
Controls collection. To be more verbose, the statement could be:

Forms!frm_PlantLog_Add.Controls(EquipmentTagString) = "Offline"
 
S

StuJol

thank you very much. works brilliant.

Stuart McCall said:
Forms!frm_PlantLog_Add(EquipmentTagString) = "Offline"

Wherever you would use a bang (!) you can use that alternative syntax. Those
are the two ways to access members of a collection, in this case the form's
Controls collection. To be more verbose, the statement could be:

Forms!frm_PlantLog_Add.Controls(EquipmentTagString) = "Offline"
 

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