473,487 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Delete All Records From All Tables

28 New Member
I am trying to delete all records from all tables in Access through VB coding. I would like to do it dynamically in case new tables are added. Here is what I have so far:

I have a form with a command button. When it is clicked, here is the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click() 
  2.  
  3. DoCmd.SetWarnings False 
  4.  
  5. DoCmd.RunSQL "DELETE * FROM [Table];" 
  6.  
  7. DoCmd.SetWarnings True 
  8.  
  9. MsgBox "All Records Deleted.", vbOKOnly, "Sendout Reports" 
  10.  
  11. End Sub 
  12.  
But is there a way to first select all tables and then delete? Or can I delete from all tables using a wildcard character?

Thanks!
Nov 9 '07 #1
1 8567
Paul Longtin
2 New Member
You just need DELETE FROM table, forget the "*"
Here is a sample of finding tables to in a database:

Expand|Select|Wrap|Line Numbers
  1. 'Using ADO
  2. Private ConDB As ADODB.Connection
  3. Private rs As ADODB.Recordset
  4. Private ProviderType As String
  5. 'Make sure you know the Provider versions
  6. 'PSI = "True" if there is a password to get into the database else "False"
  7.  
  8. 'MS Access: ProviderType = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & MyDatabase
  9.  
  10. 'MS SQL Server: ProviderType = "Provider=SQLOLEDB.1" & UserPassword & UserID & ";Integrated Security=SSPI;Persist Security Info=" & PSI & ";Initial Catalog=" & DatabaseName & ";Data Source=" & ServerName
  11.  
  12. Oracle using MS provider: ProviderType = "Provider=MSDAORA.1" & UserPassword & UserID & ";Data Source=" & ServerName & ";Persist Security Info=" & PSI
  13.  
  14. Oracle using MS provider: ProviderType = "Provider=OraOLEDB.Oracle.1" & UserID & UserPassword & ";Data Source=" & ServerName & ";DistribTx=0"
  15.  
  16. ConDB.Open ProviderType
  17.  
  18. Private tempTable As String, tempTableType As String, tempSchema As String
  19. rs.CursorLocation = adUseClient
  20. Set rs = ConDB.OpenSchema(adSchemaTables)
  21.  
  22. 'With Oracle, MySQL or if there are owners to the tables
  23. Do Until rs.EOF
  24.     tempTable = rs!TABLE_NAME
  25.     tempTableType = rs!TABLE_TYPE
  26.     If tempTableType = "TABLE" Then
  27.         tempSchema = rs!TABLE_SCHEMA
  28.         'Put you code here using (tempSchema & "." & tempTable) as the table name
  29.     End If
  30.     rs.MoveNext
  31. Loop
  32.  
  33. 'Many other databases
  34. Do Until rs.EOF
  35.     tempTable = rs!TABLE_NAME
  36.     tempTableType = rs!TABLE_TYPE
  37.     If tempTableType = "TABLE" Then
  38.         'Put you code here using (tempTable) as the table name
  39.     End If
  40.     rs.MoveNext
  41. Loop
Nov 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
10788
by: Patrizio | last post by:
Hi All, I've the following table with a PK defined on an IDENTITY column (INSERT_SEQ): CREATE TABLE MYDATA ( MID NUMERIC(19,0) NOT NULL, MYVALUE FLOAT NOT NULL, TIMEKEY ...
0
1186
by: Job Lot | last post by:
My DataGrid is bound to a DataSet and showing only those records whose Client_Liability_ID IS NULL and I am using RowFilter to do so. Following is the code: 'Set Select Command for WithdrawalDA....
6
3075
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
3
3878
by: Tim Marshall | last post by:
HI all, Access 2003, Jet back end. Rather than annoy my users in a particular app by having relationships with enforced relational integrity refuse to delete a record with related records, I'm...
3
2084
by: John Rivers | last post by:
Hello, I think this will apply to alot of web applications: users want the ability to delete a record in table x this record is related to records in other tables and those to others in...
2
7641
by: nekiv90 | last post by:
Greetings, I have to delete older policies and its related records in other tables. The deletion from the parent table will trigger the deletion of relevant records from about 30 something...
6
3836
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
1
4477
by: jpr | last post by:
Hello, My database has 5 tables. WHen I add data to one table, it runs an append query that copies three records to other 4 tables. The main table is MASTER. The data I copy are: ID, SSN and...
5
4130
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I...
3
3510
by: Phil Stanton | last post by:
I have a form based on a complex query (Lots of tables) If I delete a record, everything appears to be OK. Get the message "Youa are about to delete 1 record ....". I say yes. The record count...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.