Results 1 to 2 of 2
2003-04-18, 11:13 #1
- Join Date
- Feb 2001
- Youngstown, Ohio, USA
- Thanked 0 Times in 0 Posts
Check 'if exist' on creating table by vba (2000 SR1)
I have a module that when run will create two linked tables, using the run-date to determine which tables to link to, and what to name the tables. The module has an 'On Error GoTo' control that will display a message and halt the code if an error is encountered, but I would like to include a more graceful check first. I would like something like 'if not exist %tablename% then create %tablename%' so that it can simply bypass any unnecessary steps instead of completely erroring out.
I have an Excel function that uses a loop to run through the named ranges in a spreadsheet, and I was thinking something of the sort could be used to solve my problem - but I couldn't find how to gain access to the database's list of tablenames.
2003-04-18, 11:26 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: Check 'if exist' on creating table by vba (2000 SR1)
You could use this function:
Function TableExists(TableName As String) As Boolean
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Loop through AllTables collection.
For Each obj In dbs.AllTables
If obj.Name = TableName Then
TableExists = True
Set obj = Nothing
Set dbs = Nothing