Button to delete all records of a table

  • Thread starter Thread starter Frank Situmorang
  • Start date Start date
F

Frank Situmorang

Hello,

Can anyone help me how can we make it just to pressed the button, then all
records in a table will be deleted/ purge out.

Background:

I want to distrtibute copy of my church database to all pastors of our
church. In my membership database, there is a child table of Notes...in which
a church clerck can put a note for the member. Before I give the copy of the
database to pastors, I want to purge out all the content of the table of
Notes, so that later I can collect it from them and inport their notes table
to be combined with the central database which is the one a scretary has. I
have made an append query for that.

Thanks for any help.

Frank
 
In the click event of the button try:

CurrentDb.Execute "Delete * From YourTableName;"
 
I'd suggest adding a msgbox to ask if they really want to do this.

I wrote a billing program in MS BASIC many years ago and asked that
question.
Then she asked that I modify to to ask twice. (At which point she realized
I was right about demanding she back things up.)
Then she asked that I modify to to ask three times.
 
I'd suggest adding a msgbox to ask if they really want to do this.

I wrote a billing program in MS BASIC many years ago and asked that
question.
Then she asked that I modify to to ask twice. (At which point she realized
I was right about demanding she back things up.)
Then she asked that I modify to to ask three times.

"I have told you once,
I have told you twice -
What I tell you three times is true!"
- _The Hunting of the Snark_

And sometimes that's not enough. Sometimes the user is NOT right.
 
If MsgBox ("Are you really, really, REALLY sure?", vbYesNo) = vbYes Then
MsgBox "Say 'Please Delete' 4 times and click your heels twice",
vbOKOnly
End If
 
If MsgBox ("Are you really, really, REALLY sure?", vbYesNo) = vbYes Then
MsgBox "Say 'Please Delete' 4 times and click your heels twice",
vbOKOnly
End If

<chuckle>

I've actually used:

Dim strMsg As String
strMsg = "Clicking OK will permanently delete all the information about this
animal, and all the accounting information about it. This information CANNOT
BE RECOVERED. Are you absolutely certain that you want to do this?"

When the client saw the message she changed her mind about having the delete
button on the form...
 
Okay, I wanna piggy back this thread, since if I post a new someone will probably refer me here.
I am having the same problem and am really new to a lot of the VBA stuff as well. As I read through all of your posts and try certain things, I learn that I have no idea where to place the coding. Below is the coding for my purge records button. I am trying to delete all records from a table named Records(original right), but once again I can't figure out where to put it all. I also need the message that asks if they are sure they want it deleted. Please help as this is a ginormous pain for me.
Thanks
Private Sub Command40_Click()
On Error GoTo Err_Command40_Click

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Exit_Command40_Click:
Exit Sub
Err_Command40_Click:
MsgBox Err.Description
Resume Exit_Command40_Click

End Sub
 
Okay, I actually got the button to delete all records, but cannot figure out the message box. I will continue to try, but it is more than annoying because I'll copy script from this post and will end up with a bunch of red data.

Okay, I wanna piggy back this thread, since if I post a new someone will probably refer me here.
I am having the same problem and am really new to a lot of the VBA stuff as well. As I read through all of your posts and try certain things, I learn that I have no idea where to place the coding. Below is the coding for my purge records button. I am trying to delete all records from a table named Records(original right), but once again I can't figure out where to put it all. I also need the message that asks if they are sure they want it deleted. Please help as this is a ginormous pain for me.
Thanks
Private Sub Command40_Click()
On Error GoTo Err_Command40_Click

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Exit_Command40_Click:
Exit Sub
Err_Command40_Click:
MsgBox Err.Description
Resume Exit_Command40_Click

End Sub
 
Also, is there a way to have it automatically close the form once the purge record button has been clicked and Yes has been selected.
 
Back
Top