Using varible with Dlookup

  • Thread starter Thread starter BRC
  • Start date Start date
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.
 
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
*************
 
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
 
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
 
Back
Top