Delete All Button

ddrew

seasoned user
Local time
Today, 03:10
Joined
Jan 26, 2003
Messages
911
Can anyone tell me what the code would beif I wanted to create a button for 'Delete All Records' from a form.

You may ask why I want to do this! I have a database which has the ability to create a playlist for Disco. At the end of the Gig the guy wants to delete all the records from the playlist in order to do a new one for next time.

I cant belive this is difficult, but for me!:confused:
 
Hey

mySQL = "Delete * from tableName"
DoCmd.RunSQL mySQL
 
More?

If you need more info just post a new reply and I'll go over things like new buttons and forms and such.
PB
 
Poor VB

Sorry my VB's very weak, more please!
 
Sorry so late, been in meetings

OK,

Create a form by going to the forms tab.
Click new.

Select the wizard to help you through creating the form.
If the form opens, close it.
Right click on the form in the form list and choose 'Design'


To put on a button:
Select 'View' from the main menu.

Select 'ToolBox'

When the toolbox opens, hover your mouse over the tools until you find 'Command Button'.

Click on it. The mouse will change to a new icon until you drop the command button on the form.

A wizard may pop up. Just make it something simple like:
Form Operation,.....Close Form and finish the wizard.

Right click on the button and choose 'build event'. This will take you to the code window where this code will be.


On Error GoTo Err_Command9_Click


DoCmd.Close

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click


Paste in the previous code over DoCmd.close

Save and close.
Double click to launch
Enjoy
PB
 
Not Working

OK tryed all that, but it comes up with variable not defined and highlights mySQL = . Any Ideas!
 
Option explicit

Look at the very top of the code text. If

'Option Explicit' is written there, then you are required to declare all variables.

Dim mySQL As String
mySQL = "Delete * from tableName"
DoCmd.RunSQL mySQL

PB
 
It Worked

OK that worked. It removes all the records, but it only shows that after I do the delete then close the form then reopen it. How do I put in a 'requerry' I guess it would be?
 

Users who are viewing this thread

Back
Top Bottom