Results 1 to 19 of 19

Thread: Deleting Tables

  1. #1

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408
    I asked this question a long time ago and I didn't understand what people told me. How do you delete a table. The code I am using to creat a table is.
    Code:
    Dim rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\mydb.mdb", False, False, ";pwd=password")
    
    Set tdfTable = dbsData.CreateTableDef(Text1.Text)
    
    With tdfTable
    .Fields.Append .CreateField("amount", dbCurrency)
    End With
    
    dbsData.TableDefs.Append tdfTable
    
    rcdTable.Close
    dbsData.Close

    Thank you so very much!!!!
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I usually use the DELETE TABLE SQL statement.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408
    I have no idea how to use sql I was told by someone else I could create tables this way.

    Code:
    Set dbsData = CreateDatabase(path, dbLangGeneral & ";pwd=password")
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path1, False, False, ";pwd=password")
    
    dbsData.Execute "CREATE TABLE Usernames (ID AUTOINCREMENT, Name TEXT, Password TEXT)"
    He also said there was a way to delete them this way but he never showed me how. Is this a SQL statement? THanks!!!
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yes. For example:
    Code:
    SELECT * FROM People WHERE LastName="Jones"
    pass that as the parameter to an OpenRecordset method to get the result.

    Use Database.Execute("DELETE TABLE MyTable") to delete a table, I think.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408
    Well this doesn't work. Anybody know why or have any suggestions? Thanks!!
    Code:
    Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
    
    dbsData.Execute ("DELETE TABLE Currency.mdb")
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  6. #6
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Drop Table tablename

    is standard SQL for removing a table.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I thought that the DROP statement was for deleting a whole database?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    JHausmann is correct. To delete an entire table using SQL, its:
    db.Execute "DROP TABLE TableName"
    (The DELETE statement in SQL deletes records from a table, but the table itself remains intact. DROP TABLE wipes the whole table.)

    For Access databases, you can also delete a table using the following DAO code (with DAO, the method IS "Delete"):

    db.TableDefs.Delete "TableName"
    "It's cold gin time again ..."

    Check out my website here.

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I know he's correct, but I was just confirming the details in my mind. It's just that I get confused occasionally...
    My usual DB, mySQL, uses DROP DATABASE and DELETE TABLE a lot, so I'll check the details. Thanks for pointing that out, though.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Originally posted by parksie
    I thought that the DROP statement was for deleting a whole database?
    Depends on what you want to drop ...

    Drop table
    Drop index
    Drop database

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Aha. I see now .
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    At the risk of beating a dead horse, I believe you guys when you say that other DBMS's may support DROP DATABASE, but as far as I know, MS-Jet SQL for Access DB's supports only DROP TABLE and DROP INDEX (not DROP DATABASE).
    "It's cold gin time again ..."

    Check out my website here.

  13. #13
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Jet's hardly standard SQL.

  14. #14
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Agreed. But since Pitbull seemed to be doing the Access/Jet/DAO thing, that's perspective I took on this question.
    "It's cold gin time again ..."

    Check out my website here.

  15. #15

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408
    Well I can't get the sql statement to work. This is exacltly what i have:

    Code:
    Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
    
    dbsData.Execute "DROP TABLE Integer"
    I get an error that says:
    Run-time error '3295':
    Syntax error in DROP TABLE or DROP INDEX.

    I have also tried doing this:

    Code:
    Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
    
    dbsData.Execute "Delete TABLE Integer"
    I get an error that says:
    Run-time error '3075':
    Sytax error (missing operator) in query expression 'Table Integer'

    and I have also tried this:

    Code:
    Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
    
    dbsData.Execute "delete * from Integer"
    I get an error that reads:
    Run-time error '3131':
    Sytax error in FROM clause.

    and not one of them works. Why is that? Thanks!!
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  16. #16
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83

    Integer ?

    I think that the problem is the name of the table. Integer might be a reserved word. I am not sure and I do not have Access to test it on.
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  17. #17
    New Member
    Join Date
    Aug 2000
    Posts
    10

    Smile

    I'm using Access97 VB - adding to the code you started off with I have inserted a delete command (as already mentioned by BruceG above)
    Code:
    Sub CreateAndDeleteTable()
    Dim rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    Set dbsData = CurrentDb
    Set tdfTable = dbsData.CreateTableDef("Text1")
    
    With tdfTable
    .Fields.Append .CreateField("amount", dbCurrency)
    End With
    
    dbsData.TableDefs.Append tdfTable
    MsgBox "Table Created"
    dbsData.TableDefs.Delete (tdfTable.Name)
    MsgBox "Table Deleted"
    End Sub
    All without SQL - does this help?

    Alex

  18. #18
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Originally posted by PITBULLCJR
    Well I can't get the sql statement to work. This is exacltly what i have:

    Code:
    Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
    
    dbsData.Execute "DROP TABLE Integer"
    I get an error that says:
    Run-time error '3295':
    Syntax error in DROP TABLE or DROP INDEX.

    I have also tried doing this:

    Code:
    Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
    
    dbsData.Execute "Delete TABLE Integer"
    I get an error that says:
    Run-time error '3075':
    Sytax error (missing operator) in query expression 'Table Integer'

    and I have also tried this:

    Code:
    Dim strName As String, rcdTable As Recordset, dbsData As Database, tdfTable As TableDef
    
    Set dbsData = DBEngine.Workspaces(0).OpenDatabase(path & "\henry.mdb", False, False, ";pwd=password")
    
    dbsData.Execute "delete * from Integer"
    I get an error that reads:
    Run-time error '3131':
    Sytax error in FROM clause.

    and not one of them works. Why is that? Thanks!!
    I believe AKA is right and that "Integer" is a reserverd word. However, if it let you build the table with that name, you should be able to access the table by wrapping it in brackets, ie, [Integer] in your queries.

  19. #19

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Talking

    Thank you guys but if I use what Alexn gave me it works fine and dandy. It even deletes the integer table. I have many tables and I just so happened to use that one for an example. Thank You so very much for your time!!!
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width