I need to write code the checks to see if a table exists before I either delete the table or create the table through code. What do I write to check for the existance of a table?
Dan Rogotzke
Dan_Rogotzke@oxy.com
Well you can trap the error when it occurs.
I grabbed this from some code I have.
Error 3010 is generated when the table already exists
So if you put this Error routine behind a Temporary button and change the names to your table names and run it, it will give you the error number which you then trap out similar to what I did.
Public Sub MakePartMaster()
On Error GoTo Err_MakePartMaster
Dim dbs As Database, MyTableII As Recordset, SQL As String, SQL2 As String
DoCmd.Hourglass True
Set dbs = CurrentDb
Set MyTableII = dbs.OpenRecordset("Copy-PartMaster"
' Delete the table when done
DoCmd.DeleteObject acTable, "Copy-PartMaster-NEWEST"
'
Exit_MakePartMaster:
DoCmd.Hourglass False
Exit Sub
Err_MakePartMaster:
Select Case Err.Number
Case 3010
'Table already exists
DoCmd.DeleteObject acTable, "Copy-PartMaster-NEWEST"
Case 3021
'no current record
Resume NoRecs
Case Else
MsgBox "Error # " & Err.Number & " " & Err.Description, vbInformation, "In sub MakePartMaster"
End Select
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.