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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Existing Table... 1

Status
Not open for further replies.

quietstormtw

Programmer
Sep 16, 2002
81
US
Hi all, is there anyway to find out if a table exists?

I import a bunch of tables, from CSV files...sometimes I get import error tables. I would like to find out if these tables are present...then delete them. I've tried to use the code:

DoCmd.DeleteObject acTable, "table1_importerrors"

This works, only if there is a table present, which won't be the case all of the time.

Any assistance is greatly appreciated [2thumbsup]
 
This will delete any table with text "_importerrors" in the name:


Sub delete_import_error_tb()

Dim iCntr As Integer
Dim sTbName As String
ReDim aDropTables(1) As String


For iCntr = 0 To CurrentDb.TableDefs.Count - 1
sTbName = UCase(CurrentDb.TableDefs(iCntr).Name)

If InStr(sTbName, UCase("_importerrors")) > 0 Then

If aDropTables(UBound(aDropTables) - 1) <> "" Then
ReDim Preserve aDropTables(UBound(aDropTables) + 1)
End If
aDropTables(UBound(aDropTables) - 1) = sTbName
End If
Next iCntr

For iCntr = 0 To UBound(aDropTables) - 1
If aDropTables(iCntr) <> "" Then
Debug.Print aDropTables(iCntr)
DoCmd.DeleteObject acTable, aDropTables(iCntr)
End If
Next iCntr

End Sub





Mike Pastore

Hats off to (Roy) Harper
 
Hi Mike, sorry it took so long to get back to you, been extremely busy. Anyway, the code is exceptional...works perfectly each time, plus I can use it for other instances as well. Thank you very much [bigsmile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top