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

NEED HELP WITH SQL SYNTAX ON SMALL QUERY 2

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
US
What is wrong with this:
cmd.CommandText = "SELECT DISTINCT EMPNO,ACTIVESTAT " _
& "FROM BASSEARN " _
& "WHERE ACTIVESTAT="A"" _
& " ORDER BY EMPNO"
I keep getting syntax error. Have tried everything I can think of.
I can make this work ok if I type the SQL in a text box and then refer to the text property like this:
cmd.CommandText = txtBox.text
Somehow the concantenation(phew!!) must be wrong.

Thank You for any help, anybody.
TNN, Tom
TNPAYROLL@AOL.COM

TOM
 
You need to replace the " around the A with '. What you are doing is creating a couple of string rather than one.

Use:

Code:
cmd.CommandText = "SELECT DISTINCT EMPNO,ACTIVESTAT " _
                & "FROM BASSEARN " _
                & "WHERE ACTIVESTAT='A'" _
                & " ORDER BY EMPNO"

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
try debug.print cmd.commandtext to check your statement
It might be your quotes at the activestat = "A", try single quotes.
 
ColinM,
What does the "Debug.Print cmd.commandtext" do for me? I tried that in the immediate window and got back error message "Object Required". Can I somwhow check my statement there?
TNN, Tom
TNPAYROLL@AOL.COM

TOM
 
I sometimes insert debug.print in my code (not the immediate window, this is where the results are displayed) to check strings. When you hover the cursor over a string in debug mode it shows you value, but often if its a long string you can only see the start.
Its almost the same as using:
msgbox str
except the results are in the immediate window and there is no pause.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top