Dlookup doesn't go beyond first row

SiGill

Registered User.
Local time
Today, 14:25
Joined
Dec 22, 2008
Messages
72
I have a D Lookup, which works, if what I am looking up is in the first row, for some reason it won't go beyond. Can anyone help.

My code is

If 5 = DLookup("TabNo", "Running", 5) Then
DoCmd.RunMacro "Macro1"
Else
DoCmd.RunMacro "Start Table Macro"
End If

No it will look up 5 if 5 is in the top row but if it is in row 2 or onwards it won't look it up and moves onto the else part of the code.
 
in this line, your dlookup looks up the value of the field "tabno" form a table or query called "running"

the last bit is supposed to enable the dlookup to find a particular row, but 5 on its own is meaningless - so it will either error out, or just ignore it, and use the first row.

If 5 = DLookup("TabNo", "Running", 5) Then


the correct usage is shown below, where the selected row is one located by the selection parameter

tempval = DLookup("TabNo", "Running", "particularfield = 5" )

or with a variable

tempval = DLookup("TabNo", "Running", "particularfield = " & myvariable)
 
Thanks Dave

I changed it to this but I get a Data type mismatch error

If 5 = DLookup("TabNo", "Running", "[TabNo] = 5") Then

I want to look for 5 in the TabNo field of the Running table. Then if there is a 5 in there run one macro, if there isn't then run the other macro
 
Take a look again at the sample code provide by gemma-the-husky. The code below is wrong. The data mismatch error may be occurring if your "5" is actually a string rather than a number. gemma-the-husky provided a solution for both situations.
If 5 = DLookup("TabNo", "Running", "[TabNo] = 5") Then
 

Users who are viewing this thread

Back
Top Bottom