Results 1 to 8 of 8

Thread: Rebuilding/Compacting Access Database in Code

  1. #1
    Guest

    Unhappy

    Hallo

    I want to activate the rebuilding and compacting of my database after a certain period elapsed. The problem starts with the Compact-method. I have to specify a new db name (the compacted one), therefore I have to delete the old one, rename the new one so that it has the same name as the old db. For some reason the DELETE (of file) and RENAME methods are not accepted at Design-time. Is there some other way of doing this?

    I need help!

    Thank you

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    shouldn't be a problem

    Are you closing the database before trying to delete it?
    Mark
    -------------------

  3. #3
    Guest
    When I compile/Run code, the methods are not recognized by VB. So I did not even get to the point where I might get an error that database is open. Do you maybe know why?

    Thanx

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Lets have a look at your code
    Mark
    -------------------

  5. #5
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Try something like the following:
    Code:
    Private Sub CompactTheDB()
    
        Dim strOldDBName As String
        Dim strNewDBName As String
    
        strOldDBName = "C:\Whatever\TheDBName.mdb"
        strNewDBName = "C:\Whatever\TheDBName.bkp"
    
        DBEngine.CompactDatabase strOldDBName, strNewDBName
        Kill strOldDBName
        Name strNewDBName As strOldDBName
    
    End Sub
    "It's cold gin time again ..."

    Check out my website here.

  6. #6
    Junior Member
    Join Date
    Sep 2000
    Location
    Manchester, England.
    Posts
    18
    Hi Guys

    First, i should explain i am new to VB programming although i have been building Access97 apps. for about two years now.

    I have a module in an otherwise empty database that compacts and backs up another database everynight which is the one all the guys in my office log into each day.

    I'd like to build it in VB, and i'm doing ok in terms of the databse name, location etc, but here is my problem:

    Would i have to open some instance of Access to use DBEngine.CompactDatabase, or will it run from within VB as it is?

    Sorry if this is a basic question, but we all have to start somewhere.....

    I only ask as i have to do a similar thing when creating Word docs. for mail merge from within Access.

    Cheers

    Peter Gidden

  7. #7
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Note: The info below assumes that DAO is being used.

    PeterGUK:
    The answer to your question is no, you do not have to open an instance of Access to compact the DB from VB. In your VB project, go to the Project menu, then References, and check "Microsoft DAO 3.6 Object Library" (or DAO 3.51, or whatever latest version shows up there). Once this reference is set, you can access any object of the DBEngine. Thus, the code I posted earlier should work for you.

    hermanvd:
    I got your e-mail regarding your use of the ADODC, which I'm sorry to say I have not used, except for once doing a tutorial. I'm afraid I can't help you with that one.
    "It's cold gin time again ..."

    Check out my website here.

  8. #8
    Junior Member
    Join Date
    Sep 2000
    Location
    Manchester, England.
    Posts
    18
    Thanks Bruce, i'm off to give it a go.....

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