Results 1 to 10 of 10

Thread: compact mdb vb6

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    208

    compact mdb vb6

    hi there,

    do you have any sample code that will compact and repair mdb file 2002 thru vb6

    thanks,

    alexis

  2. #2
    Lively Member
    Join Date
    Mar 2007
    Posts
    78

    Re: compact mdb vb6

    check this out..

    I have found this piece of code in the code repository of this forum..

    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  
    5. On Error GoTo MyError
    6.  
    7.     Dim oApp As Access.Application
    8.  
    9.  
    10.     Set oApp = New Access.Application
    11.  
    12.     oApp.DBEngine.CompactDatabase "D:\INVOICE.mdb", "D:\INVOICECpd.mdb"
    13.  
    14.     Kill "D:\INVOICE.mdb"
    15.  
    16.     Name "D:\INVOICECpd.mdb" As "D:\INVOICE.mdb"
    17.  
    18.    
    19.     MsgBox "Compact Complete!", vbOKOnly
    20.  
    21.     oApp.Quit acQuitSaveNone
    22.  
    23.     Set oApp = Nothing
    24.  
    25.     Exit Sub
    26.  
    27. MyError:
    28.  
    29.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly
    30. End Sub

  3. #3
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: compact mdb vb6

    Quote Originally Posted by alexis23
    hi there,

    do you have any sample code that will compact and repair mdb file 2002 thru vb6

    thanks,

    alexis
    The only issue with the code posted above is that you need to have access installed on the system to compact / repair the mdb.
    Take a look at this post.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  4. #4
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: compact mdb vb6

    Make sure you reference this in VB IDE.

    Go To Project> Reference

    Microsoft ActiveX Data Objects 2.x Library
    Microsoft Jet and Replication Objects 2.x Library

  5. #5
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: compact mdb vb6

    You can also use the command line switche to run this out of sync.
    Shell("PathToAccess\Access"" \Compact"" ""DatabaseFile"" ")
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  6. #6
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: compact mdb vb6

    Hi all
    I tried this code and come with compile error:
    user define type not define
    Code:
    Option Explicit
     
    Private Sub Command1_Click()
     
    On Error GoTo MyError
     
        Dim oApp As Access.Application
     
     
        Set oApp = New Access.Application
     
        oApp.DBEngine.CompactDatabase "D:\INVOICE.mdb", "D:\INVOICECpd.mdb"
     
        Kill "D:\INVOICE.mdb"
     
        Name "D:\INVOICECpd.mdb" As "D:\INVOICE.mdb"
     
        
        MsgBox "Compact Complete!", vbOKOnly
     
        oApp.Quit acQuitSaveNone
     
        Set oApp = Nothing
     
        Exit Sub
     
    MyError:
     
        MsgBox Err.Number & " - " & Err.Description, vbOKOnly
    End Sub
    reference to this

    Microsoft ActiveX Data Objects 2.x Library
    Microsoft Jet and Replication Objects 2.x Library

    I am using vb6 and access 2003

    Thanks in advance

    Regard,
    Cesin

  7. #7
    Lively Member
    Join Date
    Nov 2007
    Location
    Rochester, NY
    Posts
    111

    Re: compact mdb vb6

    Quote Originally Posted by ksuwanto8ksd
    reference to this

    Microsoft ActiveX Data Objects 2.x Library
    Microsoft Jet and Replication Objects 2.x Library

    I am using vb6 and access 2003

    Thanks in advance

    Regard,
    Cesin
    Quote Originally Posted by zynder
    Make sure you reference this in VB IDE.

    Go To Project> Reference

    Microsoft ActiveX Data Objects 2.x Library
    Microsoft Jet and Replication Objects 2.x Library
    You have to set the references to the lib files through your project->references view, as zynder explained earlier.
    Please use the search function prior to posting a question and see if someone's already answered it.
    -If I helped you, please rate me, as I'd do the same for you =)
    -Remember to select the Resolved option for your post when you've gotten the answers you need.

  8. #8
    Lively Member
    Join Date
    Mar 2007
    Posts
    78

    Re: compact mdb vb6

    NEATO is right.
    you have to set the references first then try the code.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: compact mdb vb6

    Moved to database development

  10. #10
    Fanatic Member
    Join Date
    Aug 2003
    Location
    ohio, usa
    Posts
    719

    Re: compact mdb vb6

    when a DB is compacted is it also repaired??

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