tags:

views:

71

answers:

1

I have a folder full of 100-odd Access97 files. I need to update them all to Access2003.

I could do it manually, but using VBA would probably be a lot faster.

Does anyone that would have a snippet that would do this? Or an alternative suggestion?

+3  A: 

DBEngine.CompactDatabase olddb, newdb,, dbVersion40 should work.

Note that you will want to check your references after words and do some cleanup. I used the following code in one my systems that I was working with in A97 and making an A2000 and A2002 MDB. The idea being that the conversion added a few references that I wanted to get rid of programmatically so I never had to worry about them. You'll probably want to log the output to a .txt file named the same as the MDB and check things as you go along.

Function tt_FixReferences() As Boolean

Dim ref As Reference
Dim stMsg As String, intPosn As Integer, strRefPathName As String, blnCompile As Boolean


    On Error GoTo tagError
    For Each ref In Access.References
        If ref.IsBroken Then
             VBA.MsgBox "Ref" & ref.name & " is broken."
        Else
 '           Debug.Print ref.Name & ", " & ref.FullPath
            Select Case Access.SysCmd(acSysCmdAccessVer)
            Case 9#  ' Access 2000
                If ref.name = "VBIDE" Then
                    strRefPathName = ref.FullPath
                    References.Remove ref
                    VBA.MsgBox strRefPathName & " removed."
                    blnCompile = True
                End If
            Case 10# ' Access 2002
                If ref.name = "VBIDE" Or ref.name = "OWC10" Then
                    strRefPathName = ref.FullPath
                    References.Remove ref
                    VBA.MsgBox strRefPathName & " removed."
                    blnCompile = True
                End If
            End Select
        End If
    Next ref
    tt_FixReferences = True
    If blnCompile = True Then
        Call Access.SysCmd(504, 16483)
        MsgBox "Compiled."
    End If


tagExit:
    Exit Function

tagError:
    If err = 48 Then ' ?????
        If VBA.Len(VBA.Dir(ref.FullPath)) > 0 Then
            References.AddFromGuid ref.Guid, ref.Major, ref.Minor
            Resume Next
        Else
            stMsg = "Reference " & vbCrLf & "'" & ref.FullPath & "'" _
                    & vbCrLf & "couldn't be restored."
            VBA.MsgBox stMsg, vbCritical + vbOKOnly, _
                    "Error restoring references."
            tt_FixReferences = False
            Resume tagExit
        End If
    Else
        stMsg = "An unexpected error occurred." _
            & vbCrLf & "Number: " & err.Number _
            & vbCrLf & "Description: " & err.Description
        VBA.MsgBox stMsg, vbCritical + vbOKOnly, _
            "Error restoring references."
        tt_FixReferences = False
        Resume tagExit
    End If
End Function
Tony Toews
Make sure you backup all your files first :)
Toby Allen
Presumably all these files would be part of your daily backup. Also note that the CompactDatabase creates a new MDB file and that you'd only be working with the references in the new MDB file. So strictly speaking no backup required. Of course I'd still make a copy. <smile>
Tony Toews