Referencing Dlookup in subform

M

Melissa

I am writing a macro to reference a control on a subform. My macro worked
great when I was in the subform only, but now that I am working in the main
form, it isn't working. Not a big shock, but I don't know how to properly
address the subform control. Can anyone please help? Or if anyone knows a
great resource for referencing controls I would appreciate that even more.
The Dlookup function has given me the biggest headache of all!

This is the DLookup Function I have so far. . .
Products - Table where ItemNumber is the Primary Key
PurchaseOrders - Main Form with subform frmOrders and controlname ItemNumber
DLookUp("[ItemNumber]","Products","[ItemNumber] =" &
'[Forms]![PurchaseOrders]![frmOrders].Form![ItemNumber]')
 
D

Douglas J. Steele

Assuming ItemNumber is a numeric field,

DLookUp("[ItemNumber]","Products","[ItemNumber] =" &
[Forms]![PurchaseOrders]![frmOrders].Form![ItemNumber])

If it's text,

DLookUp("[ItemNumber]","Products","[ItemNumber] ='" &
[Forms]![PurchaseOrders]![frmOrders].Form![ItemNumber] & "'")

Note that depending on how you added frmOrders as a subform, it's possible
that the name of the subform control on form PurchaseOrders may be something
other than frmOrders. Use the name of the subform control if they are, in
fact, different.
 

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