Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I have an SQL statement that

Status
Not open for further replies.

VoodooRage

Programmer
Oct 9, 2002
43
US
Hi,

I have an SQL statement that contains a DLookup as follows (pasted from the query builder):
DoCmd.RunSQL = "SELECT CPUMstr.CPUSN, CPUMstr.CPUMfg, " _
& " CPUMstr.CPUModel, CPUMstr.CPUAsset, " _
& "DLookUp("[CPUSN]","Users","[CPUSN] = " _
& "'" & [CPUSN] & "'") AS Expr1, " _
& " CPUMstr.CPUBench FROM CPUMstr " _
& "WHERE (((DLookUp("[CPUSN]","Users","[CPUSN] = '" & [CPUSN] & "'")) Is Null) AND ((CPUMstr.CPUBench)=True));

The problem is with the literals in the Dlookup. I can't seem to get the SQL to work in VB because of the literals required in the Dlookup. When I try to code the syntax for the text portion of the dlookup "[CPUSN]" to ''[CPUSN]'' at the end of the Dlookup where ''[CPUSN] ='' & '' ' '' & ''[CPUSN]'' & '' ' '' & ) is where the dlookup seems to get confused.

Thanks for any help, you people are super!

The query runs fine in the Query Builder but like I said the literals in the Dlookup are throwing the VB SQL into a tither.
 
Replace the quote marks (") in the literal with apostrophes (') and see if that helps.

AvGuy
 
Hmm. Don't use DCount would be my advice. How about:

Code:
DoCmd.RunSQL = "SELECT CPUMstr.CPUSN, CPUMstr.CPUMfg, " _
             & "CPUMstr.CPUModel, CPUMstr.CPUAsset, " _
             & "Users.CPUSN As Expr1 " _
             & "FROM CPUMstr LEFT JOIN Users " _
             & "ON CPUMstr.CPUSN = Users.CPUSN " _
             & "CPUMstr.CPUBench FROM CPUMstr " _
             & "WHERE Users.CPUSN Is Null AND " _ 
             & "CPUMstr.CPUBench=True;

You might want to check that this does the same as your query carefully!!!!! [pc2]
 
From what I can See the Location of your " marks are incorrrect. Try this:


DoCmd.RunSQL = "SELECT CPUMstr.CPUSN, CPUMstr.CPUMfg, CPUMstr.CPUModel, CPUMstr.CPUAsset, " & DLookup("[CPUSN]", "Users", "[CPUSN] = '" & [CPUSN] & "'") & " AS Expr1, CPUMstr.CPUBench FROM CPUMstr WHERE (((" & DLookup("[CPUSN]", "Users", "[CPUSN] = '" & [CPUSN] & "'") & ") Is Null) AND ((CPUMstr.CPUBench)=True));"


I did not use the & _ to shorten the line.

Pierre
 
hi

in response to your Dlookup syntax..try this
set a variable, in this example, quote to equal a " (quote).
then concatenate the quote variable as in the example below
this has worked fine for me using DoCmd.RunSQL

Let quote = Chr$(34)

"DLookUp(" + quote + "[from_date]" + quote + "," + quote + "qtr_to_process" + quote + ")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top