Question : Dlookup in Access

I am trying to return a dlookup value (titem) when tfixedrate > 0

if I use a static variable the lookup works but breaks when I substitute a variable for the contract ID. I know its just a missing " or something but been looking at it for the last hour.. Arrgh

THanks in advance for the Help
Code Snippet:
1:
2:
3:
4:
5:
'Working with static number 4065 
xitem = DLookup("[titem]", "tbl_UsageSort", "[tContractID] = 4065 And [tfixedrate] > 0") 'Archive Usage
 
'Breaks Working with variable tusagesort.tContractID (which equals 4065)
xitem = DLookup("[titem]", "tbl_UsageSort", "[tContractID] = " & tusagesort.tContractID And [tfixedrate] > 0 )
Open in New Window Select All

Answer : Dlookup in Access

xitem = DLookup("[titem]", "tbl_UsageSort", "[tContractID] = " & varaibale & " And [tfixedrate] > 0")

Or if variable is non numeric

xitem = DLookup("[titem]", "tbl_UsageSort", "[tContractID] = '" & variable & "' And [tfixedrate] > 0")

in this case single quote then double quote at beginning and double quote and single quoate at the end


Kelvin
Random Solutions  
 
programming4us programming4us