DlookUp Problems

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I am using Dlook up on my ordering system to get the price of the good.
I have a combo box that i select the product and the i want it to look
up the price from the tblProducts

i have the following code
Price = DLookup("[Price]", "tblproducts", "[IDNumber] = Me.IDNumber")

when i run it i get the following error

Run-time Error 2001

You canceled the previous operation






Can any one tell me how to fix this
 
The error message indicates that there is an error in the expression.

Try concatenating the number onto the end of the 3rd string, i.e.:
Me.Price = DLookup("[Price]", "tblproducts", "[IDNumber] = " &
Me.IDNumber)

If IDNumber is actually a Text field (not a Number field), you need extra
quotes:
Me.Price = DLookup("[Price]", "tblproducts", "[IDNumber] = """ &
Me.IDNumber & """")

If it still fails, perhaps there is a space in the file name, or perhaps the
IDNumber in the form is null.

An alternative approach would be to change the RowSource of the combo so
that it contains the price. You can then assign the value from the column of
the combo without having to look it up, e.g.:
Me.Price = Me.IDNumber.Column(1)

Note that the first Column is zero, the second is one, and so on.
 
Back
Top