DlookUp Problems

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
 
A

Allen Browne

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.
 

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

Similar Threads

Query to show latest price 2
dlookup 2
Dlookup 6
Criteria On Dlookup 1
Access Control on subform / combo box requesting parameter 0
DLOOKUP 2
DLOOKUP question 4
DLookup Function 2

Top