VBA/Excel/Access/Word/Access/Table Delete

Материал из VB Эксперт
Версия от 15:46, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Deleting a Table from a Database

   <source lang="vb">

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

</source>
   
  


Deleting a Table with SQL command

   <source lang="vb">

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

</source>