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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLOOKUP error 1

Status
Not open for further replies.

malbreht

Technical User
Dec 8, 2006
63
SI
Hi!

I want to do a lookup on tblProduct before entering the price of the product in tblPurchaseProduct.

Code:
tblPurchaseProduct ([u]PurhaseProduct_ID[/u], Purchase_ID, Product_ID, [b]Price[/b], Quantity, Cancel)
tblProduct ([u]Product_ID[/u], Name, [b]Price[/b])

The names in my form are the same - Product_ID and Price.

I copied the code from Nortwind db, but an error occurs - red text (actually yellow).

Code:
Private Sub Product_ID_AfterUpdate()

    Dim strFilter As String
    
    ' Evaluate filter before it's passed to DLookup function.
    strFilter = "Product_ID = " & Me!Product_ID
    
    ' Look up product's unit price and assign it to UnitPrice control.
    [COLOR=red]Me!Price = DLookup("Price", "tblProduct", strFilter)[/color]

Exit_Product_ID_AfterUpdate:
    Exit Sub

End Sub

Does anybody know, what could be the problem?

Tnx, mare
 

DLookup returns NULL if the value was not found!

And do provide the error that comes up
 
Oh, sorry: the error window displays:

run-time error '3464':

Data type mismatch in criteria expression.


Tnx!
 

If it is a Text data type ...
strFilter = "Product_ID = '" & Me!Product_ID & "'
 
Hey!

If I delete:

Dim strFilter As String

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

and erase strFilter from the red row, it does start to lookup the price, but for each product returns only the price of the first product (ID=1), which is wrong...

Any clues?

Thank you very much!
 
Your suggestion returns the same - everytime just the price for the first product.

Anybody?
 
And this?

Me!Price = DLookup("Price", "tblProduct", "Product_ID=" & Me!Product_ID)
 
Thank you very much, Jerry - but it still doesn't work. The line is still yellow or it returns the wrong price (the first one).

Product_ID is text, if I haven't written yet.

Thanks a lot!
 
You just did!

Me!Price = DLookup("Price", "tblProduct", "Product_ID='" & Me!Product_ID & "'")
 
Oh, man! I love you! :)

It works! Many, many thanks and sorry for not describing the type of the field.

Mare
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top