Solved

Delete all data from a SQL Server Table using VBA

Posted on 2009-07-06
8
617 Views
Last Modified: 2013-11-27
How do I delete all data from a SQL Server Table using VBA.  I was using the following for a Access table but it doesn't work for SQL Server:
  DoCmd.RunSQL "DELETE * FROM Commitment_Outlook_bak"
0
Comment
Question by:schmir1
  • 5
  • 3
8 Comments
 
LVL 12

Expert Comment

by:kevin_u
ID: 24790125
http://doc.ddart.net/mssql/sql70/ta-tz_10.htm

truncate table Commitment_Outlook_bak

or

delete from Commitment_Outlook_bak
0
 

Author Comment

by:schmir1
ID: 24790168
What code to I need?  Truncate table doesn't work by itself.
0
 
LVL 12

Expert Comment

by:kevin_u
ID: 24790192
DoCmd.RunSQL "truncate table  Commitment_Outlook_bak"
0
 
LVL 12

Accepted Solution

by:
kevin_u earned 500 total points
ID: 24790193
DoCmd.RunSQL "DELETE FROM Commitment_Outlook_bak"
but this is slower.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:schmir1
ID: 24796238
I tried:
  DoCmd.RunSQL "truncate table  Commitment_Outlook_bak"
And got this error:
  Error Number 3129
  Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

Note: I'm running this in VBA.
0
 

Author Comment

by:schmir1
ID: 24796491
I tried:
  DoCmd.RunSQL "DELETE FROM Commitment_Outlook_bak"
I got error:
  Error Number 3086
  Could not delete from specified tables.
Fired up Server management Studio and I CAN'T DELETE records with it either.
Guess I need to ask another question.
0
 

Author Comment

by:schmir1
ID: 24798581
I had to relink the tables then it worked.  Thanks for you help.
0
 

Author Closing Comment

by:schmir1
ID: 31600412
Works great.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now