Dlookup with variable

latex88

Registered User.
Local time
Today, 08:15
Joined
Jul 10, 2003
Messages
198
I've tried all kinds of combination but I just can't figure out the syntax.
Dim SomeVariable as String
Dim NewVariable as String
SomeVariable = Something
NewVariable = dlookup ("Field1Name", "TableName", "[Field2Name] = SomeVariable")

I know it works fine when I take out the SomeVariable and replaces with actual value, but since I need to make this statement dynamic, I need to insert a variable. What is the exact syntax to make this work?
 
Hi Latex,

The problem is your statement is saying "Where [Field2Name] = SomeVariable. Literally SomeVariable. You need to include it as a variable

For text data:
dlookup ("Field1Name", "TableName", "[Field2Name] ='" & SomeVariable & "'")

For Date data;
dlookup ("Field1Name", "TableName", "[Field2Name] =#" & SomeVariable & "#")

For numeric data;
dlookup ("Field1Name", "TableName", "[Field2Name] =" & SomeVariable)
 
Thank you so much. I looked everywhere on the web. Your syntax, at least for the text works great. I've not tried the other data types yet.
 

Users who are viewing this thread

Back
Top Bottom