473,469 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Syntax Error on a DLookup Criteria

137 New Member
Expand|Select|Wrap|Line Numbers
  1. If DLookup("TS_ID", "TestsForScripts", "[Ref_ID]=" & Me.Ref_ID & " AND " & "[ExpectedResult]='" & Me.ExpectedResult & "'") = "" Then
Can anyone see anything wrong with this code? It keeps throwing up a Run Time Error 3075 message, saying there's a syntax error and I can't spot any.

Ref_ID is a numerical field, and ExpectedResult is a string based field.

Thanks.
Apr 11 '11 #1

✓ answered by TheSmileyCoder

I would guess that your problem comes from the fact that you have a single quote as a value in your expected results. Access so neatly handles the special charecters as long as they are in a field that we seldom remember (myself included) to handle them in vba.

Try this:
Expand|Select|Wrap|Line Numbers
  1. If DLookup("TS_ID", "TestsForScripts", "[Ref_ID]=" & Me.Ref_ID & " AND " & "[ExpectedResult]='" & Replace(Me.ExpectedResult,"'","''") & "'") = "" Then

7 5067
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
You are trying to compare to an empty string. Usually Access does not store empty strings. If the field has not been used, it will be null, not a zero length string. You need to understand that there is a big difference between the two.

If you are worried that a DLookup could return null, there are a few things to do:
Enclose it in Nz, like so:
Expand|Select|Wrap|Line Numbers
  1. NZ(Dlookup_GOES_HERE,"")
If Dlookup returns a value the value gets returned from nz. If Dlookup returns Null, the empty string is returned.

A simpler way, which only works for strings, is to take advantage of the fact that: Null & ""=""
Expand|Select|Wrap|Line Numbers
  1. If Dlookup() & ""="" then 
  2.   'Null was returned
  3. End IF
Apr 11 '11 #2
Adam Tippelt
137 New Member
While I understand what you say, that isn't where the problem lies. The problem seems to exist in the dlookup itself, not the comparison.

The entire error message that comes up is:

Run-time error ‘3075’:

Syntax error (missing operator) in query expression ‘[Ref_ID]=410 AND [ExpectedResult]=’Invalid login details are blocked by the system, and the user is prompted that the details aren’t valid.”.

Don't know if that gives any clues.

From what I've deduced, the problem seems to be with ExpectedResult. This is only one field of many that are supposed to be in the criteria, and doing a dlookup with all fields except ExpectedResult runs without a problem. :S
Apr 11 '11 #3
MikeTheBike
639 Recognized Expert Contributor
Hi

Not withstanding TheSmileyCoder's excellent advice, I think your DLookUp() should be like this

Expand|Select|Wrap|Line Numbers
  1. DLookup("TS_ID", "TestsForScripts", "[Ref_ID]=" & Me.Ref_ID & " AND [ExpectedResult]='" & Me.ExpectedResult & "'")
assuming Ref_ID is numeric and ExpectedResult is text

??

MTB
Apr 11 '11 #4
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I would guess that your problem comes from the fact that you have a single quote as a value in your expected results. Access so neatly handles the special charecters as long as they are in a field that we seldom remember (myself included) to handle them in vba.

Try this:
Expand|Select|Wrap|Line Numbers
  1. If DLookup("TS_ID", "TestsForScripts", "[Ref_ID]=" & Me.Ref_ID & " AND " & "[ExpectedResult]='" & Replace(Me.ExpectedResult,"'","''") & "'") = "" Then
Apr 11 '11 #5
Adam Tippelt
137 New Member
Once again SmileyCoder, you seem to have struck gold! The single quote in the value seems to be causing problems, and putting in your suggestion has solved the problem. I'll have to remember this one!

Thanks for the help.
Apr 11 '11 #6
Adam Tippelt
137 New Member
So much for me remembering this one - just got linked back to this thread while searching for an answer to the same problem!
Jun 1 '11 #7
NeoPa
32,556 Recognized Expert Moderator MVP
LoL.

An important point to remember though Adam is What to Include in a Thread Asking for Help.
Jun 2 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
3
by: Jack | last post by:
What is the syntax for the criteria in DLookup in a subform to refer to a control (MyControl) on the subform? I have tried the following and none seem to work: " = " &...
3
by: shifty shaker | last post by:
I've modified sql text and now i'm getting a syntax error that I cannot figure out....anyone? error occurs at the Insert Into line but the entire function is given in case you need it. ---...
21
by: Thelma Lubkin | last post by:
I would like my DLookup criteria to say this: Trim(fieldX) = strVar: myVar = _ DLookup("someField", "someTable", "Trim(fieldX) = '" & strVar & '") I don't believe that this will work, and I...
4
by: tasmontique | last post by:
Hello everyone, I keep getting a syntax error in my update statement. The only thing that I notice is that although the columns in my table have the same name as the fields on the form the...
3
by: injanib via AccessMonster.com | last post by:
Hello Access Monsters, I have a table with three columns. "CostCenter", "ProjectNumber", "GLCode" On my form I have three texboxes, "txtCostCenter", "txtProjectNumber" and "txtGLCode". the...
19
by: ramprat | last post by:
Hi everyone, This one is stumping me really good. The query entered in my filter below will work as a stand alone query in Access but I keep getting a syntax error when I try to run it through a...
5
by: rolltide | last post by:
I've seen many similar threads, but despite repeated efforts I cannot figure out my problem. I am running Access 2003, VB 6.5, Office XP Pro. Code excerpt is below (you can see where I've tried...
2
by: GLEberts | last post by:
I can not seem to get rid of this syntax error - hope someone can help out. the error I am getting is: Run time Error 3075 Syntax error missing operator in query expression =name I have...
1
by: JpjVB | last post by:
I'm having difficulty filtering a form using a multiselect list box when using some Allen Browne code. I get the error "Syntax Error (missing operator)in query expression '( IN (""Sydney"London)'. -...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.