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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Error - Unknown cause, can anyone help?

Status
Not open for further replies.

rosdancer

Programmer
Jul 26, 2002
14
CA
When I run the following code I get this error Syntax error (missing operator) in query expression 'validation='countryCode' AND'.
I'm not sure what the problem is and therefore I'm not sure how to change this code.
Thanks in advance for the help.

Roslyn

Private Sub Form_Load()
lngCurrentID = 1
strSql = "SELECT * FROM ValidationList WHERE fldvalidSection=" & SQLText("countryCode") & " AND order=" & SQLNumber("1")
countryCodes.Open strSql, gConnection, adOpenStatic, adLockOptimistic
lockCountryCode
If countryCodes.BOF Or countryCodes.EOF Then
MsgBox "There are no countries please add one.", vbOKOnly, "Country Maintenance - VisualToPowership"
txtCountry = ""
txtDescription = ""
countryCodes.Close
unlockCountryCode
Else
countryCodes.Close
displayRecord
End If
End Sub
 
I don't know what the SQLText function is, but I'll bet you should omit the quotes from the argument, i.e., use
Code:
SQLText(countryCode)
in your built-up strSQL.
 
What you could also do is stop your code at this line

strSql = "SELECT * FROM ValidationList WHERE fldvalidSection=" & SQLText("countryCode") & " AND order=" & SQLNumber("1")

step over that line, then see what the value of strSQL is

Transcend
[gorgeous]
 
Thanks for the help guys, I figured out what is was,

order is special word in SQL, can't use it as a variable.

SQLText and SQLNumber change strings into text and number that are translated into readable code.

Also harebrain, countrycode is a string not a variable containing a string, so it needs the quotes.

Roslyn
 
Roslyn,

Well, that took all the fun out of my wild guess! :) Glad you figured it out! Although I can't quite make sense of why, if countrycode is a literal, you'd build the strSQL as you did instead of just putting it all together in one string, e.g.,
Code:
strSql = "SELECT * FROM ValidationList WHERE fldvalidSection = 'countryCode' AND ..."
Nevermind that string concatenation is inefficient, you just made extra work for yourself.


Cassie,

Thanks for the pointer to the SQLText function. Cool! I don't think it's what Roslyn was using, though, as the signature is different (two args rather than one.) I'm snagging it for myself. Not that I haven't created a similar function, but somebody actually documented the one you found! ;-)
 
Good point, I don't usually use an actual string I ususally use a variable. Thanks for the suggestion.

Roslyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top