Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleUse DAO and SQL to create and drop database tables
KeywordsSQL, DROP TABLE, CREATE TABLE
CategoriesDatabase
 
Use the SQL DROP TABLE and CREATE TABLE statements.
 
' Drop table TargetTable.
Private Sub cmdDropTable_Click()
Dim db As Database
Dim dbname As String
Dim dbopen As Boolean

    On Error GoTo DropError
    dbname = App.Path
    If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
    dbname = dbname & "droptabl.mdb"
    Set db = OpenDatabase(dbname)
    dbopen = True

    db.Execute "DROP TABLE TargetTable"

    db.Close

    MsgBox "Table dropped"
    Exit Sub

DropError:
    MsgBox "Error " & Format$(Err.Number) & _
        " dropping table." & vbCrLf & _
        Err.Description
    If dbopen Then db.Close
End Sub

' Drop table TargetTable.
Private Sub cmdCreateTable_Click()
Dim db As Database
Dim dbname As String
Dim dbopen As Boolean

    On Error GoTo DropError
    dbname = App.Path
    If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
    dbname = dbname & "droptabl.mdb"
    Set db = OpenDatabase(dbname)
    dbopen = True

    db.Execute _
        "CREATE TABLE TargetTable (Field1 INTEGER)"

    db.Close

    MsgBox "Table created"
    Exit Sub

DropError:
    MsgBox "Error " & Format$(Err.Number) & _
        " creating table." & vbCrLf & _
        Err.Description
    If dbopen Then db.Close
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated