Code Examples For RunCommand Constants

Convert A Database

acCmdConvertDatabase

The following function converts an earlier version of Access to the latest version. Beware that if an error occurs you will need to switch back to the original to OK the error message.

'***************** Code Start *******************
SendKeys information
' Code by Terry Wickenden

Function ConvertDatabase(PathOld As String, PathNew As String)
    Dim acApp As Access.Application
    
    On Error GoTo ErrHandler
    
    Set acApp = CreateObject("Access.Application")
    SendKeys PathOld & "{Enter}"
    SendKeys PathNew & "{Enter}"
    acApp.DoCmd.RunCommand acCmdConvertDatabase
    
ExitPoint:
    On Error Resume Next
    acApp.Quit
    Set acApp = Nothing
    Exit Function

ErrHandler:
    Select Case Err.Number
        Case 2501
            'Action cancelled probably caused by
            'trying to convert a database of the latest version
            MsgBox "Unable to convert " & PathOld
            Resume ExitPoint
        Case Else
            MsgBox Err.Number & vbCrLf & Err.Description
            Resume ExitPoint
    End Select
End Function

'****************** Code End ********************