On Wed, 6 Dec 2006 08:41:30 -0500, Kevin M wrote:
"fredg" <fg******@examp le.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.Exec ute "DeleteQueryNam e",dbFailOnErro r
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.Execu te "DeleteQueryNam e",dbFailOnErro r
Change "DeleteQueryNam e" 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_Clic k()
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.SetWarnin gs False
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnin gs True
I hope this helps.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail