Running a delete query from a form

Aenathras

Registered User.
Local time
Today, 13:50
Joined
Nov 8, 2006
Messages
10
I have code in my form using Do.Cmd:

stDocName = "QueryName"
DoCmd.OpenQuery stDocName, acNormal, acEdit

which is code created using the Access Wizard.

I have another delete query that I wish to run from the form but when I edit the QueryName to be the name of the query it doesn't run and if I use the wizard to select the query from the list the delete queries do not appear. The query runs fine when executed separately - i.e. not from the form.

Is there an alternate syntax to the above to run delete queries or something that I need to change in the delete query itself so that it can be run from my form?

All help welcome
 
Code:
DoCmd.OpenQuery "QueryName"

As it's an Action query, you don't need the stuff after it that you already had.

You will find that you start getting the 'You are about to delete....so many records message.' To stop this, the following should be used:

Code:
With DoCmd
    .SetWarnings False
    .OpenQuery "QueryName"
    .SetWarnings True
End With
 

Users who are viewing this thread

Back
Top Bottom