Lookup Criteria returning #Error (1 Viewer)

kevnaff

Member
Local time
Today, 06:53
Joined
Mar 25, 2021
Messages
141
Hello All

I have a continuous subform called ContractsReadSubform, that is based on a query called QueryContractsSubform.

One of the fields in the query is called CodeNo, which relates to the unique equipment number of a device. Every CodeNo has a serial number which is stored in the ImportEquipment table.

On the subform I want to be able to show the serial number of the CodeNo in an unbound text box. In the ImportEquipment table, the CodeNo field is called Code No with a space.

I have attempted this using the below example:

DLookUp("SerialNumber","ImportEquipment","Code No = " & Me![CodeNo]")

However the criteria that I am entering, always shows #Error in the unbound text box.

Can anybody spot where I am going wrong with this?

Thanks
 
Local time
Today, 07:53
Joined
Feb 27, 2023
Messages
43
Fieldnames with blanks need to be enclosed by square brackets like you did(unnecessarily) on CodeNo and the last double quote is wrong:
Code:
DLookUp("SerialNumber","ImportEquipment","[Code No] = " & Me!CodeNo)
 

kevnaff

Member
Local time
Today, 06:53
Joined
Mar 25, 2021
Messages
141
Fieldnames with blanks need to be enclosed by square brackets like you did(unnecessarily) on CodeNo and the last double quote is wrong:
Code:
DLookUp("SerialNumber","ImportEquipment","[Code No] = " & Me!CodeNo)


Thanks for your help.

However, the unbound text box is now showing #Name? instead of #Error.

I will look in to why this is.
 
Local time
Today, 07:53
Joined
Feb 27, 2023
Messages
43
Me is only valid in VBA Code. In form design properties you have to reference the form by name from the forms collection:
Code:
Forms("FormName")
and avoid the Bang-Operator.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:53
Joined
Feb 19, 2002
Messages
43,445
DLookUp("SerialNumber","ImportEquipment","[Code No] = " & Me!CodeNo)
the statement is out of context. if it is actually in the Control Source, it needs to be:
=DLookUp("SerialNumber","ImportEquipment","[Code No] = " & CodeNo)
 

Users who are viewing this thread

Top Bottom