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

VBA- long SQL command 1

Status
Not open for further replies.

Ramy27

Technical User
Apr 26, 2005
63
GB
Trying to connect to DB from Excel using VBA.
The following SQL command has some errors. I'm quite sure it's got to do with " ' " etc....but I couldn't figure out. Can someone help?


DeleteSQL = "DELETE * FROM TimeSheet WHERE " _
& "Name = '" & CStr(wb.Sheets("TimeSheet").Cells(3, 2).Value) & "'" _
& "Date = '" & FormatDateForSQL(TRangeC.Cells(i, 1).Value, conn) & "'" _
& "AmPm = '" & CStr(TRangeC.Cells(i, 3).Value) & "'"

---------------------------------
Your help is much appreciated, R.
---------------------------------
 
You need to seperate the where clause condition with the word AND. Like this...

Code:
DeleteSQL = "DELETE * FROM TimeSheet WHERE " _
        & "Name = '" & CStr(wb.Sheets("TimeSheet").Cells(3, 2).Value) & "'" _
        & " AND Date = '" & FormatDateForSQL(TRangeC.Cells(i, 1).Value, conn) & "'" _
        & " AND AmPm = '" & CStr(TRangeC.Cells(i, 3).Value) & "'"

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks.

---------------------------------
Your help is much appreciated, R.
---------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top