Bob P
Bob P

Reputation: 237

Issue using DLookUp function in Access

Ok so I have a text box on my main form and I want it to show the quantity of a product chosen from a drop down list.

Now there is a complication, there are 3 stock locations for each product, but this is simplified as I have 3 different levels stored on the same record for a product, with different column names.

So what I need to do is search for the name of the correct column to find the right stock location (again from a drop down).

My stock level column heading is stored in the variable "Branch" which is a string.

Here is my code.

Me.txtSourceDescQty.Value = DLookup(Branch, "[products/stock]", "[Product Code] = " & Me.cmbSource.Value)

Error message

This is the error I get. 'Stock Level' is the column header for one of the stock locations, which is stored under the variable "Branch" in the line of code.

cmbSource is the combo box where the product code is selected.

Upvotes: 2

Views: 437

Answers (1)

thornomad
thornomad

Reputation: 6777

I think Me.cmbSource.Value needs to appear in quotes:

Me.txtSourceDescQty.Value = DLookup(Branch, "[products/stock]", "[Product Code] = '" & Me.cmbSource.Value & "'")

Upvotes: 3

Related Questions