Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

runtime error 2471 Dlookup 1

Status
Not open for further replies.

davyre

Programmer
Oct 3, 2012
197
AU
Hi guys,
i got this error runtime 2471, the expression you entered as a query parameter produces this error: '[Model]'
the code is this
Code:
 modelNumber = Worksheet.Cells(excelLine, "B")
        modelNumber = "'" & modelNumber & "'"

 modelID = DLookup("[ModelID]", "TblModel", "[Model] = " & modelNumber & "")
I am 100% sure there is a field named Model in TblModel. What is the issue here? Thanks!
n.b modelNumber is a string variable datatype
 
update:
i changed the code into
Code:
modelID=DLookUp("[ModelID]", "TblModel", "[Model]=[COLOR=#CC0000]'[/color]" & modelNumber & "[COLOR=#CC0000]'[/color]")

but still saying error, this time the error message: syntax error (missing operator) in query expression '[Model]="UFWW-1-CB"'".

anyone help? thanks
 
update 2:
I change to something like this:
Code:
ModelID = DLookup("ModelID", "TblModel", "ModelNum=' & modelNumber & '")

now it says error invalid use of Null. Whats going on? Checked the modelNumber variable, and it has a value so there should be no usage of Null value
 
How do I use Debug.Print? I already add debug.print below the coding ModelID=Dlookup(..), then when I execute it the immediate window did not show anything, as the compiler stops at the row ModelID=Dlookup(..) (I think)...
 
Put a break point prior to calling the DLookup and then open the debug window (press Ctrl+G). Find out the value of modelNumber

Code:
? modelNumber

Then paste the value into
Code:
? DLookup("ModelID", "TblModel", "ModelNum='...Your Value Here...'")

Then try change your code to:

Code:
ModelID = DLookup("ModelID", "TblModel", "ModelNum='[b][red]"[/red][/b] & modelNumber & [b][red]"[/red][/b]'")

Duane
Hook'D on Access
MS Access MVP
 
You already have quotes around the field.

Code:
modelNumber = [red]"'"[/red] & modelNumber & [red]"'"[/red]

and you are adding more of them in the DLookup

Also, your syntax is incorrect. It should be
Code:
DLookup("ModelID", "TblModel", "ModelNum=" & modelNumber )
 
dhookom said:
... since I never use that method.

Nor do I.

It just seems wrong to have variable values enclosed in quotes floating around in my code. At best it's confusing and error-prone as in this case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top