DLookup Problem

SiGill

Registered User.
Local time
Today, 11:29
Joined
Dec 22, 2008
Messages
72
Hi Have this code

Private Sub Command2_Click()
If Me.Text0.Value = DLookup("TableNumber", "RunningTables", _
"[TableNumberID]=" & Me.Text01.Value) Then
Me.Text1.Value = "yes"
Else
Me.Text1.Value = "no"
End If
End Sub

But I keep getting Runtime error 2001 you cancelled the previous operation. Can anyone let me know where I am going wrong

Thanks
 
Is TableNumberID a number or text? Also, when using DLookup you should use the NZ function in case your lookup returns a null.
Code:
[COLOR=red][B]Nz([/B][/COLOR]DLookup("TableNumber", "RunningTables","[TableNumberID]=" & Me.Text01.Value)[B][COLOR=red], 0)[/COLOR][/B]
But if TableNumberID is text then you need text delimiters:
Code:
[COLOR=red][B]Nz([/B][/COLOR]DLookup("TableNumber", "RunningTables","[TableNumberID]=" [COLOR=red][B]& Chr(34) [/B][/COLOR]& Me.Text01.Value [COLOR=red][B]& Chr(34)[/B][/COLOR])[COLOR=red][B], "")[/B][/COLOR]
 

Users who are viewing this thread

Back
Top Bottom