Results 1 to 8 of 8

Thread: Run Access compact and repair from VB6

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Location
    Littlehampton, W Sussex GB
    Posts
    203

    Post

    Does anyone know how to run Access compact and repair database from VB6 code? Also can you run an Access report using VB code? Thanks for your help.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    For Repair you can use:

    DBEngine.RepairDatabase "C:\MyDB.mdb"

    For Compacting:

    Code:
        Dim strTempDB As String
        Dim strDBName As String
        
        strDBName = "C:\MyDB.mdb"
        strTempDB = "C:\Temp.mdb"
        DBEngine.CompactDatabase strDBName, strTempDB
        Name strTempD As strDBName
    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]



  3. #3
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    Hello Serge. I tried using this codes but I think i am missing a project reference or component. Could you please tell me what reference or component I should include with my project? Thanks a bunch.
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  4. #4
    Hyperactive Member VB IT's Avatar
    Join Date
    Feb 2003
    Posts
    381

    Question DbEngine

    VB Code:
    1. Dim strTempDB As String
    2.     Dim strDBName As String
    3.    
    4.     strDBName = "C:\MyDB.mdb"
    5.     strTempDB = "C:\Temp.mdb"
    6.     DBEngine.CompactDatabase strDBName, strTempDB ' What is This?
    7.     Name strTempD As strDBName

    Any on know what is DbEngine?
    Sorry for Bad English.

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    You need to set a reference to Microsoft DAO Library.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  6. #6
    Hyperactive Member VB IT's Avatar
    Join Date
    Feb 2003
    Posts
    381

    Wink Thanks

    Originally posted by pnish
    You need to set a reference to Microsoft DAO Library.
    Its Works, Thaks
    But Can I Do It With ADO?
    Sorry for Bad English.

  7. #7
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    I'm not sure how to do it with ADO. Have a look at this post and see if it helps:
    http://www.vbforums.com/showthread.p...hreadid=201558
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  8. #8
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    VB Code:
    1. Public Function CompactDatabase(strFileName As String) As Long
    2.    
    3.     ' Add the references
    4.     ' Microsoft Jet and Replication Objects 2.x Library
    5.    
    6.     Screen.MousePointer = vbHourglass
    7.    
    8.     Dim msg               As String
    9.     Dim strFileNameBackup As String
    10.     Dim JRO               As JRO.JetEngine
    11.    
    12.     strFileNameBackup = Left(strFileName, Len(strFileName) - 3) & "~db"
    13.    
    14.     On Local Error Resume Next
    15.     Kill strFileNameBackup
    16.     On Error GoTo ErrorLine
    17.    
    18.     Name strFileName As strFileNameBackup
    19.    
    20.     Set JRO = New JRO.JetEngine
    21.     JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileNameBackup, _
    22.                         "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileName & ";Jet OLEDB:Engine Type=5"
    23.    
    24.     Kill strFileNameBackup
    25.     Screen.MousePointer = vbDefault
    26.     Exit Function
    27.    
    28. ErrorLine:
    29.    
    30.     CompactDatabase = Err.Number
    31.    
    32. End Function
    oh1mie/Vic


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