Dlookup

T

Tom

HI there

I am using the dlook up function, and its working fine
till i dont use the criteria, once i put in the criteria
it dosent work.
Following is the code which is not working

Dim varX As Variant
varX = DLookup("[F_Flag]", "Flag Support", "[P_Name]=" &
Forms![output calculation]!P_Name)

If i remove the criteria itw working fine.

I would appreciate if someone would help me on this.

Thank you.
 
R

Rick Brandt

Tom said:
HI there

I am using the dlook up function, and its working fine
till i dont use the criteria, once i put in the criteria
it dosent work.
Following is the code which is not working

Dim varX As Variant
varX = DLookup("[F_Flag]", "Flag Support", "[P_Name]=" &
Forms![output calculation]!P_Name)

If i remove the criteria itw working fine.

If Len(Nz(Forms![output calculation]!P_Name,""))= 0 Then
varX = DLookup("[F_Flag]", "Flag Support")
Else
varX = DLookup("[F_Flag]", "Flag Support", "[P_Name]='" & Forms![output
calculation]!P_Name & "'")
End If
 
S

Shaun Beane

Tom, note the extra set of quotes Rick added to the criteria - that "may" be
your only problem. If the [P_Name] field is text, you need to wrap the
criteria in quotes.

--
Shaun Beane, MCT, MCDBA
http://dbageek.blogspot.com
Dim varX As Variant
varX = DLookup("[F_Flag]", "Flag Support", "[P_Name]=" &
Forms![output calculation]!P_Name)

If i remove the criteria itw working fine.

If Len(Nz(Forms![output calculation]!P_Name,""))= 0 Then
varX = DLookup("[F_Flag]", "Flag Support")
Else
varX = DLookup("[F_Flag]", "Flag Support", "[P_Name]='" & Forms![output
calculation]!P_Name & "'")
End If
 
Top