docmd.openquery

M

MoonBlosm

I am attempting to run a delete query. I don't want the delete query to
delete all records just records where [projectnum] = me.projectnum. When I
do a docmd.openquery, I can delete them all. I do not know how to send a
parameter to this delete query so it only deletes specified records. I have
the code in a button on a form. IF this cant be done, does anyone know of a
better way to delete specific records from a button on a form? Thanks for
your help in advance!
 
K

Klatuu

--
Dave Hargis, Microsoft Access MVP

Here is a better way:

Dim strSQL As String

strSQL = "DELETE * FROM MyTable WHERE [projectnum] = " & Me.projectnum &
";"
Currentdb.Execute strSQL, dbFailOnError

The above syntax in the SQL assumes projectnum is a numeric field. If it is
text, use this syntax:

strSQL = "DELETE * FROM MyTable WHERE [projectnum] = """ & Me.projectnum
& """;"
 
M

Marshall Barton

MoonBlosm said:
I am attempting to run a delete query. I don't want the delete query to
delete all records just records where [projectnum] = me.projectnum. When I
do a docmd.openquery, I can delete them all. I do not know how to send a
parameter to this delete query so it only deletes specified records. I have
the code in a button on a form. IF this cant be done, does anyone know of a
better way to delete specific records from a button on a form?


Dim strSQL As String
strSQL = "DELETE * FROM table " _
"WHERE projectnum = " & me.projectnum
CurrenDb.Execute strSQL, dbFailOnError
 
M

MoonBlosm

Thank you... I knew there had to be an easier way. You guys are always so
helpful!

Klatuu said:
--
Dave Hargis, Microsoft Access MVP

Here is a better way:

Dim strSQL As String

strSQL = "DELETE * FROM MyTable WHERE [projectnum] = " & Me.projectnum &
";"
Currentdb.Execute strSQL, dbFailOnError

The above syntax in the SQL assumes projectnum is a numeric field. If it is
text, use this syntax:

strSQL = "DELETE * FROM MyTable WHERE [projectnum] = """ & Me.projectnum
& """;"

MoonBlosm said:
I am attempting to run a delete query. I don't want the delete query to
delete all records just records where [projectnum] = me.projectnum. When I
do a docmd.openquery, I can delete them all. I do not know how to send a
parameter to this delete query so it only deletes specified records. I have
the code in a button on a form. IF this cant be done, does anyone know of a
better way to delete specific records from a button on a form? Thanks for
your help in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top