By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,064 Members | 1,542 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,064 IT Pros & Developers. It's quick & easy.

Delete Query

P: n/a
I have one table and have created a form from that table. Also, I have
created a delete query. I want to but a button on the form which will delete
all records from the table; however, I cannot get anything to work. I know
this is probably simple for more experienced Access users. Any help would be
greatly appreciated.

Thanks
Kevin


Dec 5 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Tue, 5 Dec 2006 17:14:34 -0500, Kevin M wrote:
I have one table and have created a form from that table. Also, I have
created a delete query. I want to but a button on the form which will delete
all records from the table; however, I cannot get anything to work. I know
this is probably simple for more experienced Access users. Any help would be
greatly appreciated.

Thanks
Kevin
"Cannot get anything to work" doesn't give us any useful information.
What exactly is the SQL of your delete query?
Does that work by itself?

If so, then code the command button click event:

CurrentDb.Execute "DeleteQueryName",dbFailOnError

If the query doesn't work by itself, post the query SQL.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Dec 5 '06 #2

P: n/a

"fredg" <fg******@example.invalidwrote in message
news:11******************************@40tude.net.. .
On Tue, 5 Dec 2006 17:14:34 -0500, Kevin M wrote:
>I have one table and have created a form from that table. Also, I have
created a delete query. I want to but a button on the form which will
delete
all records from the table; however, I cannot get anything to work. I
know
this is probably simple for more experienced Access users. Any help would
be
greatly appreciated.

Thanks
Kevin

"Cannot get anything to work" doesn't give us any useful information.
What exactly is the SQL of your delete query?
Does that work by itself?

If so, then code the command button click event:

CurrentDb.Execute "DeleteQueryName",dbFailOnError

If the query doesn't work by itself, post the query SQL.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Sorry, I don't know what the SQL is? As far as caanot get anything to work,
I tried several differenct code variations I've fond and none of them work.
I can run the delete query and it does work. I would like to be able to be a
button on the form that does the same thing. When I add a button, and choose
"run query", the delete query does not show up as a choice. Hope this makes
sense.

Thanks
Dec 6 '06 #3

P: n/a
On Wed, 6 Dec 2006 08:41:30 -0500, Kevin M wrote:
"fredg" <fg******@example.invalidwrote in message
news:11******************************@40tude.net.. .
>On Tue, 5 Dec 2006 17:14:34 -0500, Kevin M wrote:
>>I have one table and have created a form from that table. Also, I have
created a delete query. I want to but a button on the form which will
delete
all records from the table; however, I cannot get anything to work. I
know
this is probably simple for more experienced Access users. Any help would
be
greatly appreciated.

Thanks
Kevin

"Cannot get anything to work" doesn't give us any useful information.
What exactly is the SQL of your delete query?
Does that work by itself?

If so, then code the command button click event:

CurrentDb.Execute "DeleteQueryName",dbFailOnError

If the query doesn't work by itself, post the query SQL.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Sorry, I don't know what the SQL is? As far as caanot get anything to work,
I tried several differenct code variations I've fond and none of them work.
I can run the delete query and it does work. I would like to be able to be a
button on the form that does the same thing. When I add a button, and choose
"run query", the delete query does not show up as a choice. Hope this makes
sense.

Thanks
OK, so the query by itself works.

The command button wizard, unfortunately, does not include Delete
queries choices.

1) I gave you one answer in my previous reply.
After you add the command button (you don't need the wizard for this),
open the command button property sheet. Click on the Event tab.
Click on the Click event line and write:
[Event Procedure]
Then click on the little button with the 3 dots that appears on that
line.
The code window will open with the cursor flashing between 2 already
existing lines of code.
Between those 2 lines write:

CurrentDb.Execute "DeleteQueryName",dbFailOnError

Change "DeleteQueryName" to whatever the actual name of the delete
query is.
Close the code window and you are done.

2) Alternatively, if you do use the wizard when adding the command
button, select ANY query from the available list.
Then open the command button's property sheet and click on the 3 dot
button on the click event line.
When the code window opens, the existing code will be something like:

Private Sub Command553_Click()
On Error GoTo Err_Command553_Click

Dim stDocName As String

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

Exit_Command553_Click:
Exit Sub

Err_Command553_Click:
MsgBox Err.Description
Resume Exit_Command553_Click

End Sub

Change
stDocName = "AQueryName"

to whatever the Delete query name is.

Save the changes.

The 1st method (.Execute) will run the query without giving a warning
message, but will give a message if the delete query fails.

The 2nd method (OpenQuery) will give a warning message that "You are
about to delete ...etc" records, and gives you the opportunity to exit
without deleting records. If you do not wish to get the warning
message, then add 2 lines of code as indicated below:

DoCmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True

I hope this helps.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Dec 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.