You need some quotes in the Where condition of the DLookup:
varDesc = DLookup("ItemDesc", "lkpItems", "ItemNum = " & Combo14)
assuming ItemNum is a numeric field. If it's text, you need
varDesc = DLookup("ItemDesc", "lkpItems", "ItemNum = '" & Combo14 & "'")
Exagerated for clarity, that's
varDesc = DLookup("ItemDesc", "lkpItems", "ItemNum = ' " & Combo14 & " ' ")
Now, the fact that you're not getting an error on what you had indicates to
me that you haven't told Access to require the declaration of all variables.
That means it saw ItemNum as a variable (which would be initialized to
Null), and was comparing the value of the variable to the value of the combo
box. In my opinion, you should turn on mandatory declaration. You do this by
going into the VB Editor, selecting Tools | Options from the menu and
ensuring that the "Require Variable Declaration" check box on the Module tab
is checked. What this will do is add a line "Option Explicit" near the top
of each new module. (It won't do it for existing modules, though: you'll
need to go in and add that line yourself to each existing module)
Arvin's advice about putting it in the AfterUpdate event still holds.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Ricter said:
Hello all,
The following code is returning the same data, the item description in the
first row of the lookup table, no matter what I change Combo14 to... what
have I done wrong?
Private Sub Combo14_Change()
Dim varDesc As Variant
varDesc = DLookup("ItemDesc", "lkpItems", ItemNum = Combo14)
If (Not IsNull(varDesc)) Then Me![ItemDesc] = varDesc
End Sub