R6.24 Testen, ob eine Tabelle existiert

Aufgabe

Sie möchten prüfen, ob eine bestimmte Tabelle vorhanden ist.

Lösung DAO

Versuchen Sie, die entsprechende TableDef zu öffnen. Tritt ein Fehler auf, ist die Tabelle nicht vorhanden:

Function TableExists(tblname As String) As Boolean
On Error Resume Next
Dim td As DAO.TableDef
   Set td = CurrentDb().TableDefs(tblname)
   TableExists = (Err.Number = 0)
End Function

Get Microsoft Access Programmierrezepte now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.