[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Syntax error in DLookup

Posted on 2014-03-13
6
Medium Priority
?
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 39

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 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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