473,472 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to delete tables using vba from within the access 2007 database?

167 New Member
I am importing a lot of data from spreadsheets and 'import error' tables are being created. I need to be able to delete these tables using vba code in the database. Also, each of the tables are named differently so I would need to do a mask for the deletion. I have import error tables named:
"AdminSvcs$'_ImportErrors1"
"AdminSvcs$'_ImportErrors2"
"AdminSvcs$'_ImportErrors3"

I would probably need to use a mask to look for "*ImportErrors*".

I have never delete tables in the database using vba, just deleted data in the tables.
Any suggestions would be appreciated!!!
Nov 18 '10 #1
7 13719
NeoPa
32,556 Recognized Expert Moderator MVP
You can use the TableDefs collection from a database (EG. CurrentDb).

Loop through checking for whatever identifies the tables you want removed then call :
Expand|Select|Wrap|Line Numbers
  1. Call CurrentDb.TableDefs.Delete(TableName)
Nov 18 '10 #2
Mariostg
332 Contributor
Something like this. I did not test it though...
Expand|Select|Wrap|Line Numbers
  1. Public Function fncDocumentTables() As String
  2.     Dim tbl As DAO.TableDef
  3.  
  4.     For Each tbl In CurrentDb.TableDefs
  5.          If InStr(tbl.Name, "ImportErrors") Then
  6.             CurrentDb.TableDefs.Delete (tbl.Name)
  7.         End If
  8.     Next tbl
  9. End Function
  10.  
Nov 18 '10 #3
NeoPa
32,556 Recognized Expert Moderator MVP
Line #6 won't compile Mario.

Parentheses are only used when the procedure is used to return a value, or if the value is dropped explicitly by using Call. Otherwise it thinks it's dealing with an array reference.
Nov 18 '10 #4
Mariostg
332 Contributor
Yes sometime I tend to forget about parentheses rules. Interestingly enough, it compiled. So I just tried it with and without parentheses and dropped two tables... I am glad it was a dummy db.
But yes normally I don't use parentheses if I don't assign the return value to a variable.
Nov 18 '10 #5
NeoPa
32,556 Recognized Expert Moderator MVP
Shock! Horror! Don't tell me you don't have mandatory variable declaration in your projects? That code wouldn't compile in my setup (It gives Compile Error - Expected: =).

See Require Variable Declaration.
Nov 18 '10 #6
Mariostg
332 Contributor
Shame on me (more or less), I always added the Option Explicit manually. I did not know about the ability to have this set on by default. LOL. It is going to save me some typing.
I don't want to hijack the thread, but whether or not I use Option Explicit, with or with out parentheses at line 6, it compiles.
Nov 18 '10 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Well, we're discussing code suggested as a solution so I'm happy we're on topic.

I have no idea what is different then between my setup and yours that it treats that differently. Never mind.

PS I'm glad the link helped.
Nov 18 '10 #8

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

Similar topics

0
by: grahamkc | last post by:
Can anyone help? I have just upgraded from MS Access 2003 to 2007. When trying to link to Sybase tables via the usual ODBC driver method, I get to see the available tables in the database, but get an...
4
by: Cindy H | last post by:
Hi I am currently using Visual Studio.Net 2003 running on Windows Server 2000 operating system. I have used Visual Studio.net 2003 connecting to Access 2002 databases in the pass with great...
32
by: redman08 | last post by:
I have produced an Excel (2007) worksheet, with which I want to create a Pivot Table. This would all be done from a module run on an Access 2007 database. Please can anyone supply some simple...
1
by: ncsthbell | last post by:
I created a database using full blown access 2007. I have put it out for users to grab and test using Runtime Access 2007. They have entered data and now I need to go back into a table and change a...
9
by: mrzebo1 | last post by:
I have created an Access 2007 database that will be used by about 200 users. The front end will reside on the users desktop and the back end will be on a network folder. I used the database splitter...
0
by: mrzebo1 | last post by:
I have created an access 2007 database that is split into a frontend/backend. The frontend is located in the MyDocuments folder of each user. The backend is on a folder on a shared network drive. All...
0
by: ncsthbell | last post by:
I have an access 2007 database (ABC) and I want to import a form from a different 2007 access database (DEF). I go into ABC.mdb and I chose 'get external data' and I select 'access' and browse to...
0
by: rmurgia | last post by:
Does anyone know how to programmatically import an XML file into an Access 2007 database? I was thinking along the lines of DoCmd.transferText, but could not find an XML option. Thanks in advance.
0
by: john garvey | last post by:
I have a small web site running on Windows 7 with IIS7 it is written in classic ASP with an ActiveX dll that connects to and extracts/ writes/ deletes data from the database. The database is an accdb...
0
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.