473,382 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Syntax Error on a DLookup Criteria

137 100+
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 5065
TheSmileyCoder
2,322 Expert Mod 2GB
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 100+
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 Expert 512MB
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 Expert Mod 2GB
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 100+
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 100+
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 Expert Mod 16PB
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)'. -...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.