PC Review


Reply
Thread Tools Rate Thread

Delete Table Data using button on Form

 
 
mattc66 via AccessMonster.com
Guest
Posts: n/a
 
      25th Apr 2006
I need to delete the data in 10 tables prior to uploading new data. I would
like to have this as a button on a form. I have created the button and added
the click event. When I add the SQL statement I get lost in the syntax.

In looking at other help on this site – I found how to execute a SQL
statement in VB:
DoCmd.RunSQL

In a query I see the proper syntax to Delete the Data as follows:

DELETE tableName.*
FROM tableName;

When I put this all together in VB it fails.

How do I run a SQL Delete statement in VB. I will need to repeat this
statement for each table.

I know I could do this with a Query and then do a DoCmd.RunQuery – I wanted
to reduce the query step.

Thanks
Matt

--
Matt Campbell
mattc (at) saunatec [dot] com

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...dules/200604/1
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      25th Apr 2006
Dim strSQL as String

strSQL = "Delete FROM [TableNameA]"
DoCmd.RunSQL StrSQL

strSQL = "Delete FROM [TableNameB]"
DoCmd.RunSQL StrSQL

strSQL = "Delete FROM [TableNameC]"
DoCmd.RunSQL StrSQL
....

"mattc66 via AccessMonster.com" wrote:
>
> I need to delete the data in 10 tables prior to uploading new data. I would
> like to have this as a button on a form. I have created the button and added
> the click event. When I add the SQL statement I get lost in the syntax.
>
> In looking at other help on this site – I found how to execute a SQL
> statement in VB:
> DoCmd.RunSQL
>
> In a query I see the proper syntax to Delete the Data as follows:
>
> DELETE tableName.*
> FROM tableName;
>
> When I put this all together in VB it fails.
>
> How do I run a SQL Delete statement in VB. I will need to repeat this
> statement for each table.
>
> I know I could do this with a Query and then do a DoCmd.RunQuery – I wanted
> to reduce the query step.
>
> Thanks
> Matt
>
> --
> Matt Campbell
> mattc (at) saunatec [dot] com
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...dules/200604/1

 
Reply With Quote
 
=?Utf-8?B?RGVubnk=?=
Guest
Posts: n/a
 
      25th Apr 2006
Hi Matt

I created a table and a form with a command button. The following code
deletes all the data out of the table 'employerphonenumber'
Notice no semicolon. Does that help your error?


Private Sub Command3_Click()
On Error GoTo ErrorHandler
DoCmd.RunSQL "delete employerPhoneNumber.* from employerPhoneNumber"

ErrorHandler:
If 2501 Then 'User pressed Cancel
Resume Next
End If
End Sub

"mattc66 via AccessMonster.com" wrote:

> I need to delete the data in 10 tables prior to uploading new data. I would
> like to have this as a button on a form. I have created the button and added
> the click event. When I add the SQL statement I get lost in the syntax.
>
> In looking at other help on this site – I found how to execute a SQL
> statement in VB:
> DoCmd.RunSQL
>
> In a query I see the proper syntax to Delete the Data as follows:
>
> DELETE tableName.*
> FROM tableName;
>
> When I put this all together in VB it fails.
>
> How do I run a SQL Delete statement in VB. I will need to repeat this
> statement for each table.
>
> I know I could do this with a Query and then do a DoCmd.RunQuery – I wanted
> to reduce the query step.
>
> Thanks
> Matt
>
> --
> Matt Campbell
> mattc (at) saunatec [dot] com
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...dules/200604/1
>

 
Reply With Quote
 
mattc66 via AccessMonster.com
Guest
Posts: n/a
 
      26th Apr 2006
Thanks Denny that is what I needed.

Matt

Denny wrote:
>Hi Matt
>
>I created a table and a form with a command button. The following code
>deletes all the data out of the table 'employerphonenumber'
>Notice no semicolon. Does that help your error?
>
>Private Sub Command3_Click()
>On Error GoTo ErrorHandler
> DoCmd.RunSQL "delete employerPhoneNumber.* from employerPhoneNumber"
>
>ErrorHandler:
> If 2501 Then 'User pressed Cancel
> Resume Next
> End If
>End Sub
>
>> I need to delete the data in 10 tables prior to uploading new data. I would
>> like to have this as a button on a form. I have created the button and added

>[quoted text clipped - 19 lines]
>> Thanks
>> Matt


--
Matt Campbell
mattc (at) saunatec [dot] com

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...dules/200604/1
 
Reply With Quote
 
mattc66 via AccessMonster.com
Guest
Posts: n/a
 
      26th Apr 2006
Thanks John this will work great..

Matt

John Spencer wrote:
>Dim strSQL as String
>
> strSQL = "Delete FROM [TableNameA]"
> DoCmd.RunSQL StrSQL
>
> strSQL = "Delete FROM [TableNameB]"
> DoCmd.RunSQL StrSQL
>
> strSQL = "Delete FROM [TableNameC]"
> DoCmd.RunSQL StrSQL
>...
>
>> I need to delete the data in 10 tables prior to uploading new data. I would
>> like to have this as a button on a form. I have created the button and added

>[quoted text clipped - 23 lines]
>> Matt Campbell
>> mattc (at) saunatec [dot] com


--
Matt Campbell
mattc (at) saunatec [dot] com

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...dules/200604/1
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button on Form to refresh hyperlink data in table - error 1004 & 3 CAMoore Microsoft Access VBA Modules 1 24th Oct 2008 07:13 PM
IMPORT Excel data into a table via button on a form. =?Utf-8?B?VmFkaW1iYXI=?= Microsoft Access Forms 1 17th May 2005 11:04 PM
Adding selected data (using code atached to cmd button from a form) to a table Chris Microsoft Access 1 12th Jun 2004 02:27 PM
Adding selected data (using code atached to cmd button from a form) to a table Chris Microsoft Access Queries 1 12th Jun 2004 02:27 PM
Delete record data in Form and append data in table an Microsoft Access Forms 2 16th Feb 2004 09:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:08 PM.