Problem with SQL (delete) (1 Viewer)

faz88

Registered User.
Local time
Today, 12:01
Joined
Mar 31, 2008
Messages
34
Hi, i am having a problem with the statement below.

StrSQL = "DELETE * FROM tbltreatment WHERE treatmentid=" _
& Me.lstthreading.Value & ";"
CurrentDb.Execute StrSQL

The error message i get is syntax error(missing operator) in query expression 'treatmentdid='.


any help is much appreciated
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:01
Joined
Sep 12, 2006
Messages
15,755
try

where treatmentid = " _

the spaces may be required. sql is touchy about spaces

may also be the _ & syntax

normal its the other way for a line continuation
 

faz88

Registered User.
Local time
Today, 12:01
Joined
Mar 31, 2008
Messages
34
try

where treatmentid = " _

the spaces may be required. sql is touchy about spaces

may also be the _ & syntax

normal its the other way for a line continuation


i tried your suggestions. The error message doesnt show now, but the selected record still does not delete
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:01
Joined
Aug 30, 2003
Messages
36,140
Add this right before the Execute line and post the result from the Immediate window here:

Debug.Print StrSQL
 

Banana

split with a cherry atop.
Local time
Today, 04:01
Joined
Sep 1, 2005
Messages
6,318
An alternative which also will cause less bloat in the database and sidestep the whole hassle of delimiting & concatenating:

Create a Delete query and use a parameter.

Query's SQL:
Code:
PARAMETERS p TEXT(255);
DELETE FROM tbltreatment WHERE treatmentid = [p];

In VBA:

Code:
With CurrentDb.QueryDefs("DeleteTreatmentID")
   .Parameters("p") = Me.lstthreading
   .Execute dbFailOnError
End With
 

Users who are viewing this thread

Top Bottom