Article ID: 119481
Article Last Modified on 11/6/2000
Option Explicit
Function DeleteAttachment()
Dim MyDB As Database, TableName As String, I As Integer
On Error GoTo DeleteErr
Set MyDB = DBEngine.WorkSpaces(0).Databases(0)
' Prompt for the name of the attached table.
TableName = InputBox$("Enter the name of the attached_
table you want to delete.")
' First, determine if the table is an attached table. If so,
' examine all relationships in the database.
If Not ((MyDB.TableDefs(TableName).Attributes And_
DB_ATTACHEDTABLE) = 0) Then
For I = 0 To MyDB.Relations.Count - 1
' If the attached table is part of the current
' relationship, delete the relationship.
If (MyDB.Relations(I).Table = TableName) Or_
(MyDB.Relations(I).ForeignTable = TableName) Then
MyDB.Relations.Delete MyDB.Relations(I).Name
End If
Next I
' After all relationships involving this table have been
' deleted, delete the attached table.
MyDB.TableDefs.Delete TableName
End If
DeleteExit:
Exit Function
DeleteErr:
If Err = 3265 Then
MsgBox "There is no table named " & TableName
Else
MsgBox "An unexpected error (" & Err & ") occurred: "_
& Error(Err)
End If
Resume DeleteExit
End Function
Keywords: kberrmsg kbprb kb3rdparty KB119481