VBA/Excel/Access/Word/Access/Table Delete — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:46, 26 мая 2010

Deleting a Table from a Database

 
Sub Delete_Table()
   Dim cat As ADOX.Catalog
   On Error GoTo ErrorHandler
   Set cat = New ADOX.Catalog
   cat.ActiveConnection = CurrentProject.Connection
   cat.Tables.Delete "vbexTable"
   Set cat = Nothing
   Exit Sub
ErrorHandler:
   MsgBox "Table "" & "tblFilters" & _
       "" cannot be deleted " & vbCrLf & _
       "because it does not exist."
   Resume Next
End Sub



Deleting a Table with SQL command

 
Sub DeleteTable()
    Dim conn As ADODB.Connection
 
    On Error GoTo ErrorHandler
    Set conn = CurrentProject.Connection
 
    conn.Execute "DROP TABLE myTable"
    Application.RefreshDatabaseWindow
ExitHere:
    conn.Close
    Set conn = Nothing
    Exit Sub
ErrorHandler:
    If Err.Number = -2147217900 Then
        DoCmd.Close acTable, "myTable", acSavePrompt
        Resume 0
    Else
        Debug.Print Err.Number & ":" & Err.Description
        Resume ExitHere
    End If
End Sub