Language:

MS Access: IF EXISTS DROP TABLE

Language: Deutsch
Programming Language: VBA
Published by: ralf
Last Update: 5/8/2006
Views: 3639

Description

Leider ist es in MS Access nicht ohne weiteres möglich das Vorhandensein einer Tabelle abzufragen.
Dies wird gerade wenn man mit temporären Tabellen arbeitet zum Problem.
Eine Abhilfe liefert folgende VBA-Funktion:

Code

1 ' check if a table exists 2 Function tableExists(tableName As String) As Boolean 3 On Error GoTo Error_tableExists 4 Dim strTableName 5 ' assign tableName to String 6 strTableName = CurrentDb.TableDefs(tableName) 7 ' if no error occurs then set tableExists to true 8 tableExists = True 9 Exit_tableExists: 10 On Error Resume Next 11 Exit Function 12 Error_tableExists: 13 Select Case Err.Number 14 Case 3265 'Item not found in this collection 15 tableExists = False 16 Resume Exit_tableExists 17 Case Else 18 MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical 19 Resume Exit_tableExists 20 End Select 21 End Function

One comment

1

Vielen Dank! Das würde mich einige Stunden gekostet haben.

Monday, January 01, 0001 12:00:00 AM from Theo Haffmans (Utrecht, Nederland)

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS