A
alex
Delete Tables
In VBA, I’d like to delete a group of tables (both static and linked)
when the db closes…
I have this function:
Function DeleteTables() 'when mde closes, delete all tables with
suffix of 'Delete'
'If Right(CurrentDb.Name, 3) = "MDE" Then 'if current file is an mde
then
Dim db As Database
Dim tdf As TableDef
Dim lngCnt As Long
Set db = CurrentDb
For lngCnt = db.TableDefs.Count - 1 To 0 Step -1
Set tdf = db.TableDefs(lngCnt)
If Right(tdf.Name, 6) = "Delete" Then 'delete any table with
'Delete' as suffix
db.TableDefs.Delete tdf.Name
'Debug.Print (tdf.Name)
End If
Next lngCnt
Set tdf = Nothing
Set db = Nothing
'End If
End Function
I then call the function (Call DeleteTables) from the close event of a
form that remains open in my db (until the entire db is closed)
It appears that sometimes the code works, and sometimes it does not;
i.e., some tables are deleted while others are not. Also, sometimes
the tables appear to be present, but once you click the object, it
disappears. Can anyone suggest what I may be doing wrong?
Thanks,
alex
In VBA, I’d like to delete a group of tables (both static and linked)
when the db closes…
I have this function:
Function DeleteTables() 'when mde closes, delete all tables with
suffix of 'Delete'
'If Right(CurrentDb.Name, 3) = "MDE" Then 'if current file is an mde
then
Dim db As Database
Dim tdf As TableDef
Dim lngCnt As Long
Set db = CurrentDb
For lngCnt = db.TableDefs.Count - 1 To 0 Step -1
Set tdf = db.TableDefs(lngCnt)
If Right(tdf.Name, 6) = "Delete" Then 'delete any table with
'Delete' as suffix
db.TableDefs.Delete tdf.Name
'Debug.Print (tdf.Name)
End If
Next lngCnt
Set tdf = Nothing
Set db = Nothing
'End If
End Function
I then call the function (Call DeleteTables) from the close event of a
form that remains open in my db (until the entire db is closed)
It appears that sometimes the code works, and sometimes it does not;
i.e., some tables are deleted while others are not. Also, sometimes
the tables appear to be present, but once you click the object, it
disappears. Can anyone suggest what I may be doing wrong?
Thanks,
alex