Solved

Syntax error in DLookup

Posted on 2014-03-13
6
364 Views
Last Modified: 2014-03-13
What is wrong with this code?  

If DLookup("[ProdRef]", "tblProducts", "ProdRef = '" & Me.txtProductID.Column(1) & "'") <> Me.txtTransferredProdRef Then


ProdRef is a text field.

I'm getting a syntax error missing operator.

??

--Steve
0
Comment
Question by:SteveL13
6 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39926523
The DLookup syntax looks OK, but try using NZ to handle nulls:

If NZ(DLookup("ProdRef", "tblProducts", "ProdRef = '" & Me.txtProductID.Column(1) & "'")) <> Me.txtTransferredProdRef Then

Open in new window

0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39926526
Nothing obvious jumps out at me.  I would start by separating the where argument so you build it before using it in the DLookup().  That way you can stop the code and look at what you are actually sending the function as an argument.
0
 
LVL 12

Assisted Solution

by:pdebaets
pdebaets earned 250 total points
ID: 39926531
Are there any single quotes in your ProdRef field data?

You may want to try

If DLookup("[ProdRef]", "tblProducts", "ProdRef = " & chr(34) & Me.txtProductID.Column(1) & chr(34)) <> Me.txtTransferredProdRef Then

... which surrounds the value in double quotes.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 61

Expert Comment

by:mbizup
ID: 39926538
Actually, the statement as you have written it doesn't make sense.

You are looking up ProdRef where ProdRef = txtProductID.Column(1)... which is overkill for simply writing txtProductID.Column(1) without the DLookup.

Are you sure ProdRef is the correct field name in the DLookup?  I would think you might need this (looking up TransferredProdRef  instead of ProdRef, but check the field name):

If NZ(DLookup("TransferredProdRef ", "tblProducts", "ProdRef = '" & Me.txtProductID.Column(1) & "'")) <> Me.txtTransferredProdRef Then

Open in new window

0
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 39926567
... and of course if you REALLY ARE trying to lookup ProdRef where ProdRef = txtProdID.Column(1), then you can get rid of the DLookup and simplify your comparison to this (Just compare it directly):

If  Me.txtProductID.Column(1) <> Me.txtTransferredProdRef Then

Open in new window



(As an aside, is txtProductID really a combo box?   If not, the Column(1) is going to cause problems)
0
 

Author Closing Comment

by:SteveL13
ID: 39926767
Yes there were single quotes but also yes,

If  Me.txtProductID.Column(1) <> Me.txtTransferredProdRef Then

sure made it a lot easier.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now