Hi Micheal,
This is from the Microsoft Knowledge Base:
Copy and paste this code into a new module (in the database window)
-----------------------------------------------------
'INF: How to Determine If a Table or Query Exists
'Article id: Q113549
'Copyright (c) Microsoft Corporation. All rights reserved.
'************************************************* *******
' FUNCTION: IsTableQuery()
'
' PURPOSE: Determine if a table or query exists.
'
' ARGUMENTS:
' DbName: The name of the database. If the database name
' is "" the current database is used.
' TName: The name of a table or query.
'
' RETURNS: True (it exists) or False (it does not exist).
'
'************************************************* *******
Function IsTableQuery(DbName As String, TName As String) As Integer
Dim Db As Database, Found As Integer, Test As String
Const NAME_NOT_IN_COLLECTION = 3265
' Assume the table or query does not exist.
Found = False
' Trap for any errors.
On Error Resume Next
' If the database name is empty...
If Trim$(DbName) = "" Then
' ...then set Db to the current Db.
Set Db = CurrentDb()
Else
' Otherwise, set Db to the specified open database.
Set Db = DBEngine.Workspaces(0).OpenDatabase(DbName)
' See if an error occurred.
If Err Then
MsgBox "Could not find database to open: " & DbName
IsTableQuery = False
Exit Function
End If
End If
' See if the name is in the Tables collection.
Test = Db.TableDefs(TName).Name
If Err <> NAME_NOT_IN_COLLECTION Then Found = True
' Reset the error variable.
Err = 0
' See if the name is in the Queries collection.
Test = Db.QueryDefs(TName$).Name
If Err <> NAME_NOT_IN_COLLECTION Then Found = True
Db.Close
IsTableQuery = Found
End Function
-----------------------------------------------------
Then use it like this:
If IsTableQuery("", "schueler") Then
DoCmd.DeleteObject acTable, "schueler"
End If
*******************************************
HTH,
Don
Michael Magg <ao***********@aon.at> wrote in message
news:40***********************@newsreader02.highwa y.telekom.at...
Hello!
I wanna import a table with a makro, but a table with this name already
exists. So the imported table (f. i. "table") is saved as "table1". How
can I check, if such a table already exists and then delete it?
So how can I check the existence of a table?
________________________________________
Function Importieren1()
On Error GoTo Importieren1_Err
DoCmd.DeleteObject acTable, "schueler"
DoCmd.RunCommand acCmdImport
Importieren1_Exit:
Exit Function
Importieren1_Err:
MsgBox Error$
Resume Importieren1_Exit
End Function
________________________________________
Yours Jürgen