Share via

Help please with dlookup (Error 3075 : Syntax error (missing operator) in query expression )

Anonymous
2019-06-11T17:29:08+00:00

I am trying to use a dlookup to lookup up the stock code for an item from a query based on the selection a user makes in a combo box on the form......i.e. they select the description of the product and the dlookup returns the stock code..

The field name of the value I am trying to retrieve is StockCode.

The query name is qry_ProdStockCodeList.

The name of the form the form is  frmProduction.

The name of the combo box is ProdDesc.

My dlookup function looks like:

strTest = DLookup("[StockCode]", "[qry_ProdStockCodeList]", "[Desc]=" & [Forms]![frmProduction]![ProdDesc])

Each time the I make a selection of a product description in the combo box I get the following error message:

3075 : Syntax error (missing operator) in query expression '[Desc]=CORTLAND TRAY 72'. 

If I have the equal sign what operator is missing?   Can anyone help me out please.

Thanks.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Duane Hookom 26,825 Reputation points Volunteer Moderator
2019-06-11T17:42:46+00:00

Hi,

You must wrap text values inside quotes:

strTest = DLookup("[StockCode]", "[qry_ProdStockCodeList]", "[Desc]=""" & [Forms]![frmProduction]![ProdDesc] & """")

Let me know if you have more questions.

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2019-06-11T17:59:20+00:00

    Hi,

    You must wrap text values inside quotes:

    strTest = DLookup("[StockCode]", "[qry_ProdStockCodeList]", "[Desc]=""" & [Forms]![frmProduction]![ProdDesc] & """")

    Let me know if you have more questions.

    Awesome...….thanks for your help.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. ScottGem 68,830 Reputation points Volunteer Moderator
    2019-06-12T03:44:10+00:00

    In my opinion you are doing this backward. There should be no need for a Dlookup.

    The Rowsource for your ProdDesc combo should be :

    SELECT StockCode, Desc FROM ProdStockCodeList ORDER BY DESC;

    Now if you want to display both the StockCode and Desc then add an unbound text box with a ControlSource of

    =[ProdDesc]

    The combobox should be bound to a StockCode foreign Key in your table, adding the Desc is redundant.

    Was this answer helpful?

    0 comments No comments