Results 1 to 5 of 5

Thread: Deleting a table with DAO

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301
    How do I delete a table from a access database. I am using DAO.

    I have a number of tables in the database, "Rev 0","Rev 1" etc.. I have tried the following code but it does'nt work

    Code:
    Dim db As Database
    Dim rs As Recordset
    
    Set db = OpenDatabase(App.path & "\Crr_data\" & ListView2.SelectedItem.text & "\valve.mdb")
    Set rs = db.OpenRecordset(ListView5.SelectedItem.text, dbOpenDynaset)
    
    rs.Delete ' goes wrong here
    db.Close
    I get the message "No current record"

    Any ideas?

    Cheers

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    You can either use the TableDefs collection Delete method or use the DROP TABLE TableName SQL syntax. Remember to refresh the collection or the database window.

    Check Access help for those.

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301
    Cheers Paul,

    I`ve tried doing it with the tabledefs but I still cant get it to work, have you got short examples, I think I am getting the syntax wrong

    Cheers

    Rick

  4. #4
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    Dunno what happened to Paul, I had lunch with him and he's gone all quiet...

    Anyway, try this:

    Code:
    Dim db As Database
    
    Set db = OpenDatabase(App.Path & "\Crr_data\" & ListView2.SelectedItem.Text & "\valve.mdb")
    
    db.TableDefs.Delete ListView5.SelectedItem.Text

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Really, use DROP TABLE - its easier and more portable, but if you must.

    Code:
    Dim db As Database
    Set db = CurrentDb
    db.TableDefs.Delete "MyTable"
    db.TableDefs.Refresh
    Set db = Nothing
    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

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