check if table exists

caronii

New Member
Joined
Jul 13, 2004
Messages
21
I'm trying to write a module (Access 2000) to import tables from Excel. The imported tables need to overwrite the existing tables, so I want to check if the table already exists and if it does delete the table prior to importing the update.

I've tried this, but keyword "Exists" isn't valid in Access

Private Sub Update()

Dim BookingsTable As String
Dim FilePath As String

BookingsTable = "tblMens Bookings"
FilePath = "C:\Documents and Settings\kphillip\My Documents\Dollar General\Mens 1o1.xls"


If BookingsTable Exists Then
DoCmd.DeleteObject acTable, "tblMens Bookings"
End If

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, BookingsTable, FilePath, -1, "Bookings"

End Sub

KP
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi caronii,

The following function will test for the presence of a table (provided as a string argument). Paste the code into a module. Supply the table name in quotes as an arguement and the function will return T/F depending on the table's presence.

Code:
Function isTable(tblName As String) As Boolean

    Set db = CurrentDb
    
    isTable = False
    
    For Each td In db.TableDefs
        If td.Name = tblName Then isTable = True
    Next td

End Function

Use like:
isTable("myTable") and replace "myTable" with the table name in question.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,248
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top