Referencing field in subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This seems to be a fairly common topic, yet I am still unsuccessful opening
the right record. I'm trying to open another form by double clicking a field
in a subform. My vain attempts at VBA result in a dialog box asking for the
string for the where clause of docmd.openform. If you supply the value the
form opens just fine. Apparently I am not referencing the subform field
properly.

DoCmd.OpenForm "VendorData", acNormal, , "Vender = forms![cargo
manifest].form![input].vendor"

VendorData is the target form with a field of "Vender". Input is a the
subform of "Cargo Manifest" and the field with the relevent string is
"Vender".
 
Since the code goes into the module of the subform, you can just refer to
the form as Me. Then concatenate the value of the control into the
WhereCondition string:
DoCmd.OpenForm "VendorData", , , "Vender = " & Me.vendor

If Vender is a Text field (not a Number type field), you need extra quotes:

DoCmd.OpenForm "VendorData", , , "Vender = """ & Me.vendor & """"
 
Thank you for your interest and reply. I didn't provide the correct
information, which I have since stumbled across. The input form is embedded
in a subform, which has its own name, "Input Subform". Trial and error
yielded success with this string:

DoCmd.OpenForm "VendorData", acNormal, , "[Vender] = Forms![Cargo
Manifest]![Input subform]![Vendor]"

Allen Browne said:
Since the code goes into the module of the subform, you can just refer to
the form as Me. Then concatenate the value of the control into the
WhereCondition string:
DoCmd.OpenForm "VendorData", , , "Vender = " & Me.vendor

If Vender is a Text field (not a Number type field), you need extra quotes:

DoCmd.OpenForm "VendorData", , , "Vender = """ & Me.vendor & """"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Adxmedic said:
This seems to be a fairly common topic, yet I am still unsuccessful
opening
the right record. I'm trying to open another form by double clicking a
field
in a subform. My vain attempts at VBA result in a dialog box asking for
the
string for the where clause of docmd.openform. If you supply the value
the
form opens just fine. Apparently I am not referencing the subform field
properly.

DoCmd.OpenForm "VendorData", acNormal, , "Vender = forms![cargo
manifest].form![input].vendor"

VendorData is the target form with a field of "Vender". Input is a the
subform of "Cargo Manifest" and the field with the relevent string is
"Vender".
 

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

Back
Top