Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete table via VB

Status
Not open for further replies.

GirlBlonde

Programmer
Oct 30, 2007
94
AU
i want to delete a errors table that i get upon importation of data. this will be a regular occurance so i want to delete it each month after the user has imported their table otherwise they will just build up of tables. i have the below code but does not seem to be working. any ideas would be helpful.

many thanks

CurrentDb.Execute "DROP Sheet1$_ImportErrors MyTable"


Dim mySQL As String
mySQL = "DELETE * FROM Sheet1$_ImportErrors"
DoCmd.RunSQL mySQL


Energy & persistance conquer all things!
 
Try this

Sub test()
Dim dbs As Database
'Return reference to current database.
Set dbs = CurrentDb

DoCmd.DeleteObject acTable, "Sheet1$_ImportErrors"
End Sub

You code just deletes all the records


ck1999
 
How about this?

CurrentDb.Execute "DROP TABLE [Sheet1$_ImportErrors]
 
hi thanks very much for that worked great!

Energy & persistance conquer all things!
 
hi

sorry to bother again but what if i have the occasion when there is no table to delete. ie no import errors? can i write into the code an if statement so that if it exists then delete it if not then dont worry about it?

i am not that great on Vb only know basic stuff. i used the code
CurrentDb.Execute "DROP TABLE [Sheet1$_ImportErrors]"

many many thanks

Energy & persistance conquer all things!
 
Well, there is the "Is Nothing" construct you can use in conjunction with the "IF...THEN"....

"Business conventions are important because they demonstrate how many people a company can operate without."
 
You could ignore the error if it happens

Code:
Sub DeleteImportErrors()

On Error Resume Next
CurrentDb.Execute "DROP TABLE [Sheet1$_ImportErrors]"
Err.Clear
End Sub
 
This too will help
Code:
Public Function DelTable(tblName As String)
Dim tbd As TableDef
	For Each tbd In CurrentDb.TableDefs
		If tbd.Name = tblName Then
		CurrentDb.TableDefs.DELETE tblName
	End If
Next
End Function

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
A non-error messing approach
Code:
Sub DeleteImportErrors2()

If DLookup("[Name]", "MSysObjects", "[Name]='Sheet1$_ImportErrors'") & vbNullString <> vbNullString Then
    CurrentDb.Execute "DROP TABLE [Sheet1$_ImportErrors]"
End If
End Sub
 
. . . or:
Code:
[blue]   Dim Cri As String
   
   Cri = "[Name]='Sheet1$_ImportErrors'"
   
   If Not IsNull(DLookup("[Name]", "MSysObjects", Cri)) Then
       CurrentDb.Execute "DROP TABLE [Sheet1$_ImportErrors]"
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top