DLookUp Syntax for SubForm Control

D

dar

I’m pretty sure my problem is syntax.
MainForm is frmRHCF1
SubForm is RHCF1
Control on SubForm is Unit
MainForm and SubForm linked by PatientID

SubForm has Unit control:
Table = UnitAssignment
(holds therapists initials based on Unit) ex. FA2E = KW under OT

The code below works if I open SubForm stand alone.
If I open Main form, I receive Error message.

=DLookUp("Ottherapist","UnitAssignment","Unit=Forms!RHCF1.Unit")

I have searched for answers but seem to thick to grasp the correct syntax.
I went to website which had several examples, none of which I seem to make
work. So, please help here if you can.
Thanks
 
D

DrGUI

I'm assuming that the DLookup code is in the subform. It appears that the
last param is incorrect. Try the following:

=DLookUp("Ottherapist","UnitAssignment","Unit='" & Forms!RHCF1.Unit & "'")
 
D

dar

Now I get a #Name error message. AND now the stand alone subform does not
work. I copied and pasted the code below so as not to miss any punctuation.
 
D

DrGUI

Then the reference to the control is incorrect. You might want to try the
following:

Forms!RHCF1.Unit.value OR
Forms!RHCF1.Unit .text
 
D

dar

That doesn't seem to help any.
Any other suggestions: Does it matter where on the subform the control is
located?
 
J

Jeff L

When referring to a control on a subform the syntax is:

=DLookUp("Ottherapist","UnitAssignment","Unit = '" &
Forms!frmRHCF!RHCF1!Unit & "'")
 
D

dar

Thank you.
I now have that working, but need to know one more thing.
If the Unit is "abc" I do not want certain controls to be visible. I get it
to work for the first record, but as I move through records they do not show.

Ex: If Unit is "abc" Then lblLookUp.visible = false
About the 4th record the Unit changes to "xyz" but lblLookUp remains
invisible.
Which property do I want to put it in, and is there an additional condition
I need?
 

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