Thursday, February 23, 2012

Visual Basic VBA Function fExistTable

Quick function returns true or false for existence of a table in the current database.

This function does not contain error trapping.

For detailed instructions, illustrations and error trapping, see http://www.thegenericdatabase.com/2011/09/04-function-fexist-table.html

Function fExistTable(strTableName As String) As Boolean
120    Dim db As DAO.Database, i As Integer
140    Set db = CurrentDb
150    fExistTable = False
160    db.TableDefs.Refresh
170    Application.RefreshDatabaseWindow
180    For i = 0 To db.TableDefs.Count - 1
190        If LCase(strTableName) = LCase(db.TableDefs(i).Name) Then
200             fExistTable = True
210             Exit For
220        End If
230    Next i
240 Set db = Nothing
End Function