Sub Form problems with DLookup

  • Thread starter Thread starter Tal
  • Start date Start date
T

Tal

I've written a macro that will run when I change the info of a control by
using a drop down box that sources list options from a table.

The macro contains a DLookUp command that will fill in other fields in the
form by looking up data in a table.

This works perfectly when you open the form on it's own BUT if i'm running
this form as a subform within another form, I get a macro error

I'm desperate to make this work - any ideas?

Tal
 
If your Dlookup statement is referring to a field on the form the reference
is different when the form is open as a subform. A subform is not open by
itself - it is only open indirectly through the subform control on the main
form. So to reference a control on the subform, you must also reference the
subform control. With the following:

Main Form: named frmMain
subform control: named sfrmSub1
control on the subform: named txtMyControl

then from a query the correct reference to this control would be:

Forms!frmMain.form!sfrmSub1!txtMyControl

Note that 'sfrmSub1' must be the name of the subform control on the main
form. This is not necessarily the same as the name of the form object that
is referenced in the ControlSource of the subform control. To be sure, open
the main form and click once on the subform then check the name property
under the Other tab. Whatever you find there is what belongs in place of
sfrmSub1.
 
Back
Top