Delete query + variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

H
I am interested in using a query like :
val=Me.control.valu
Docmd.runSQL("DELETE from Customers Where Name=" &val

That doesn't work neithe

Docmd.runSQL("DELETE from Customers Where Name=val"

How to do this?
Thanks a lot
 
Dear Yohann:

When the string is all built, it needs to read like this:

DELETE FROM Customers WHERE Name = "John"

To code this to include the double quotes around John:

DoCmd.RunSQL("DELETE FROM Customers WHERE Name = """ & val & """")

When in doubt, do this:

Dim str As String
str = "DELETE FROM Customers WHERE Name = """ & val & """")
DoCmd.RunSQL(str)

You can then put a break point on the last line and display the
finished string in the immediate pane to check it.

A problem will occur if the variable val contains a double quote.
Additional code would be required in this case.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
Back
Top