I'm trying to run a SQL query with Excel VBA. I got the query from someone else.
vsql = "SELECT [MyTable].Cust_Name, Sum([MyTable].Amt_Paid) AS SumOfAmt_Paid, " & _
" Count([MyTable].Unit_Num) AS CountOfUnit_Num " & _
"WHERE ((([MyTable].Grp) = ""ABC1"") And " & _
"(([MyTable].Upload_Date) = [Enter Date:]) And " & _
"(([MyTable].Sub_eEmpl) = [Enter Processor's ID:]))" & _
"GROUP BY [MyTable].Cust_Name " & _
"HAVING ((([MyTable].Cust_Name) Not Like ""Deposit Total*""))"
When I run this query, I'm getting the following error message: "The SELECT statement includes a reserve word or an argument name that is misspelled or missing, or the punctuation is incorrect."
I can't figure out what is wrong (plus I've never tried to create a SQL query in VBA that requires the user to enter 2 values (Date / ID)
Any help in getting this resolved would be greatly appreciated. Thanks in advance for any help or suggestions.......
"WHERE ((([MyTable].Grp) = 'ABC1') And "
...Not Like 'Deposit Total*'))"
Use single-quotes around query values. And what are you doing with[Enter Date:]
here? - are you replacing that with a date value ? – Tim WilliamsFROM
clause, a very critical part of SQL select statement. – Parfait