SQL Delete Error

kermit5

Registered User.
Local time
Today, 17:19
Joined
Nov 2, 2001
Messages
122
I am using the Delete statement to allow the user to delete an item from a list box by clicking a command button. I have the following code in the ON CLICK property

DOCMD.RunSQL ("DELETE FROM tblSelectedFields _
WHERE SelectedField = me.lstSelectedFields, _
MasterProjectID = me.cmbProject")

I get a compile error: Expected:List Separator or ) with the WHERE highlighted.

What is wrong with my syntax?

Scott
 
try this :


change the comma (,) to an AND condition in the "where " part of the statement.
 
I still get the same error.
 
Try putting the whole SQL statement on one line instead of using the line-extension character (_). I don't think you can split up a string like this.

So Try this:

DOCMD.RunSQL ("DELETE FROM tblSelectedFields WHERE SelectedField = me.lstSelectedFields and MasterProjectID = me.cmbProject")

OR if you really want to split up the lines do it like this instead:
SQLstring="DELETE FROM tblSelectedFields" & _
" WHERE SelectedField =me.lstSelectedFields" & _
" MasterProjectID = me.cmbProject"
DOCMD.RunSQL (SQLstring)
 
Thanks!

That did the trick
smile.gif
 
That may have gotten you past the compile error, but the statement still won't work. You need to separate the variables so that VBA can parse them properly.

DOCMD.RunSQL ("DELETE FROM tblSelectedFields WHERE SelectedField = " & me.lstSelectedFields & " and MasterProjectID = " & me.cmbProject)

If the variables are text, they need to be surrounded with single or double quotes.

DOCMD.RunSQL ("DELETE FROM tblSelectedFields WHERE SelectedField = '" & me.lstSelectedFields & "' and MasterProjectID = '" & me.cmbProject & "'")
 

Users who are viewing this thread

Back
Top Bottom