Using varible with Dlookup

B

BRC

Cans someone tell me whats wrong with this code?

****************
Private Sub ItemName_AfterUpdate()
Dim strFilter As String

' Evaluate filter before it's passed to DLookup function.
strFilter = "itemname = " & Me!ItemName

MsgBox (strFilter)
' Look up product's unit price and assign it to UnitPrice control.
Me!subclass = DLookup("subclass", "Parts", strFilter)
end sub
*******************
the message box displays the correct itemname but the dlookup is
causing error 2001. I beleive it has to do with the use of
"strfilter" in the criteria of the dlookup. I took this from the
orders form in Northwind sample database. thaks for any suggestions.
 
B

BRC

Cans someone tell me whats wrong with this code?

****************
Private Sub ItemName_AfterUpdate()
Dim strFilter As String

' Evaluate filter before it's passed to DLookup function.
strFilter = "itemname = " & Me!ItemName

MsgBox (strFilter)
' Look up product's unit price and assign it to UnitPrice control.
Me!subclass = DLookup("subclass", "Parts", strFilter)
end sub
*******************
the message box displays the correct itemname but the dlookup is
causing error 2001. I beleive it has to do with the use of
"strfilter" in the criteria of the dlookup. I took this from the
orders form in Northwind sample database. thaks for any suggestions.
Correction
the code should read
**************
Private Sub ItemName_AfterUpdate()
Dim strFilter As String

' Evaluate filter before it's passed to DLookup function.
strFilter = "itemname = " & Me!ItemName

MsgBox (strFilter)
' Look up product's subclass and assign it to subclass control.
Me!subclass = DLookup("subclass", "Parts", strFilter)
end sub
*************
 
K

Ken Snell \(MVP\)

Is ItemName a text data type? If yes, delimit the value with ' characters:

Private Sub ItemName_AfterUpdate()
Dim strFilter As String
' Evaluate filter before it's passed to DLookup function.
strFilter = "itemname = '" & Me!ItemName & "'"
MsgBox (strFilter)
' Look up product's subclass and assign it to subclass control.
Me!subclass = DLookup("subclass", "Parts", strFilter)
End Sub
 
B

BRC

Is ItemName a text data type? If yes, delimit the value with ' characters:

Private Sub ItemName_AfterUpdate()
Dim strFilter As String
' Evaluate filter before it's passed to DLookup function.
strFilter = "itemname = '" & Me!ItemName & "'"
MsgBox (strFilter)
' Look up product's subclass and assign it to subclass control.
Me!subclass = DLookup("subclass", "Parts", strFilter)
End Sub

--

Ken Snell
<MS ACCESS MVP>






- Show quoted text -

Thanks Ken, iss resolved
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top