Results 1 to 2 of 2

Thread: Compact Database via VB

  1. #1
    Guest

    Lightbulb

    Hey,

    I'm using the following code to (try to) compact a database.

    Private Sub Compact_Database()

    Dim jro As jro.JetEngine

    Dim OldConn As String
    Dim NewConn As String

    Set jro = New jro.JetEngine

    OldConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PROJECTEN\AdmICS\Databases\Test.mdb;PWD=test"
    NewConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PROJECTEN\AdmICS\Databases\TestComp.mdb;PWD=test"

    jro.CompactDatabase OldConn, NewConn

    End Sub

    Coming to the last line it gives a fault:
    'Could not find installable ISAM'.

    Can anybody tell me with this fault means or how I can alter
    my code in order by to make it work.

  2. #2
    Addicted Member LAURENS's Avatar
    Join Date
    Jan 2000
    Location
    Utrecht, the Netherlands
    Posts
    138
    I always do something like this, simply pass the original name and the name of the compressed database to the DBEngine.CompactDatabase method.

    Don't forget to backup first

    Beware !!!
    Untested code, typed it straight into this box cause our internet pc's are not on our network, I think it's correct though.
    Beware !!!


    Code:
    Dim strTemp As String
    Dim strOriginal As String
    Dim strMessage As String
    
    Dim lngOldSize as Long
    Dim lngNewSize as Long
    
       strTmp = pstrDataBaseDir & pstrDataBaseName
       strOriginal = pstrDatabaseDir & pstrDatabaseName & "org"
       lngOldSize = FileLen(strTmp)
    
       Name strTmp As strOriginal
       
       strCompressed = strTmp
        
    ' Compress database to it's original name.
       DBEngine.CompactDatabase strOriginal, strCompressed, , , ";PWD=" ' Here your Password
       
       lngNewSize = FileLen(strCompressed)
       
       strMessage = "Action completed" & vbLf & vbLf & _
                    "Old size: " & CStr(lngOldSize) & _
                    "New size: " & CStr(lngNewSize) & vbLf
    
       MsgBox strMessage
    Remember to make sure there are no connections to the database left in the program and make sure there are no users in the database anymore.
    Regards,
    Laurens

    Using VB5 Enterprise edition SP3
    VB6 Enterprise edition SP5

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