Question : VBA Variable as DLookup Criteria

Hi,

how can i use a Vartype called Var1 as the criteria for Dlookup

=Dlookup("Factor","MAN","[Diference]='Var1'")

but that fails

my Var1 = the result of two Doubles being subtracted, but the value "Factor" is a text field

the Var1 has to be at 2 decimals pointsa to match difference properly

Thanks

Answer : VBA Variable as DLookup Criteria

DLookup("[Factor]","Mon","[Difference] = " & Var1)

This assumes you have already set the value of var1 before getting here. It doesn't really matter what data type Factor is

If difference is numeric then the expression would be

"[Difference] = " & var1

If text

"[Difference] = '" & Var1 & "'"  start with double quote, single then double quote in the middle set and double, single & then double at the end.

If a date

"[Difference] = #" & var1 & "#"


Kelvin
Random Solutions  
 
programming4us programming4us