Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete all data from a SQL Server Table using VBA

Posted on 2009-07-06
8
Medium Priority
?
694 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Accepted Solution

by:
kevin_u earned 2000 total points
ID: 24790193
DoCmd.RunSQL "DELETE FROM Commitment_Outlook_bak"
but this is slower.
0
 

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

604 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