View Full Version : Using Variables in lookup function


aqif
07-15-2001, 07:22 PM
Hi All http://www.access-programmers.co.uk/ubb/smile.gif

I am using lookup function like this

DLookup(" [Table1]![Field1] ", "Table1", " [Table1]![Field2]= [txtbox1]")

its working fine for me but I want to use a variable name in criteria like

Dim var1 as integer

var1 = 1

DLookup(" [Table]![Field1] ", "Table", " [Table]![Field2]= var1")

I have also tried

DLookup(" [Table1]![Field1] ", "Table1", " [Table1]![Field2]= [var1]")

but its not working, rite now I m storing the value in an invisible text box and then referring the name of that text box name in criteria expression. Is there a way to directly use declared variables in criteria expression.

Cheers!
Aqif

Jack Cowley
07-15-2001, 08:54 PM
There are a number of syntactical errors in your function. Here is what it should look like:

DLookup("[FieldName]","TableName","[FieldInTable] = " & Var1)

Take a look at the examples in the Help files under DLookup function for an explanation of the various arguments of the function.

[This message has been edited by Jack Cowley (edited 07-15-2001).]

aqif
07-15-2001, 09:54 PM
Thanxx....it was of great help to me http://www.access-programmers.co.uk/ubb/smile.gif