Pacific Database

Home | Contact | FAQs | View Cart

A world of information at your fingertips

Determine the version of Access from Access itself

To determine the version of Access a particular database was created by, check the AccessVersion property.

Public Function GetAccessVersion(sFileName As String, _
                                 Optional bShowError As Boolean = False) _
                                 As String
    'Return the version of Access that created the file
    
    Dim ws As DAO.Workspace
    Dim db As DAO.Database
    Dim vVer As Variant
    
    Set ws = CreateWorkspace("wSpace", "Admin", "", dbUseJet)
    Set db = ws.OpenDatabase(sFileName)
    
    On Error Resume Next
    
    vVer = db.Properties("AccessVersion")
    If (Err <> 0) Then
        Err.Clear
        vVer = db.Properties("Version")
        If (Err <> 0) Then
            If (bShowError = True) Then
                DoCmd.Beep
                MsgBox "Error " & Err.Number & _
                        vbCrLf & _
                        Err.Description, _
                        vbOKOnly + vbExclamation, _
                        "Could not detect Access version"
            End If
            
            vVer = "Unknown"
            GoTo Proc_Exit
        End If
    End If
    
    Select Case vVer
        Case 1#: vVer = "Access 1.0"
        Case 1.1: vVer = "Access 1.1"
        Case 2#: vVer = "Access 2.0"
        Case 6.68: vVer = "Access 95"
        Case 7.53: vVer = "Access 97"
        Case 8.5: vVer = "Access 2000"
        Case 9.5: vVer = "Access 2002/2003"
        Case Else: vVer = "Unknown"
    End Select
    
Proc_Exit:
    GetAccessVersion = vVer
    
    db.Close
    ws.Close
    Set db = Nothing
    Set ws = Nothing
End Function

 

Determine the version of Access directly from the file

To determine the version of Access a particular database was created by, open the database file itself, and check the value at certain file offsets.

Attribute VB_Name = "modVersion"
Option Explicit
Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, Source As Any, ByVal Length As Long)
Public Function GetMDBVersion(sFileName As String) As String
' Scan a file and determine MDB version
' Returns 09.50 Access XP
'         08.50 Access 2000
'         07.53 Access 97
'         06.68 Access 95
'         2.0   Access 2.0
'         1.0   Access 1.x (does not distinguish 1.0 and 1.1)
    Dim lFileLen As Long
    Dim lFileNum As Long
    Dim bytFileData() As Byte
    
    lFileNum = FreeFile
    
    Open sFileName For Binary Access Read As lFileNum
    
    ' Get the length of the file
    lFileLen = LOF(lFileNum)
    
    ReDim bytFileData(1 To lFileLen)
    
    'Fill the array with the contents of the original file
    Get lFileNum, , bytFileData
    Close lFileNum
    
    ' Get the Jet Version
    ' Jet3 or Jet4
    ' Always found at Offset 157
    ' Jet 4  =  342E3000
    ' If offset 156 = 0, then we have Jet 3 or earlier
    
    If bytFileData(157) = 0 Then
        'Jet 3 versions
        GetMDBVersion = GetJet3Version(bytFileData)
    Else
        'Jet 4 versions
        GetMDBVersion = GetJet4Version(bytFileData)
    End If
End Function
Private Function GetJet4Version(bytData() As Byte) As String
    Dim lCtr As Long
    Dim bytCurValue As Byte
    Dim lTemp As Long
    
    'Loop Lthrough the bytes in the file
    For lCtr = 1 To UBound(bytData) - 24
        ' We are looking for
        '         09.50 Access XP -> 48 57  46  53 48
        '         08.50 Access 2K -> 48 56  46  56 58
        
        bytCurValue = bytData(lCtr)
        
        Select Case bytCurValue
            Case 48 '"0"
                ' Remember UNICODE!
                ' Grab the next 4 bytes
                CopyMem lTemp, bytData(lCtr + 1), 4
                
                If lTemp = 771766528 Then
                    ' Grab the next 4 bytes
                    CopyMem lTemp, bytData(lCtr + 1 + 4), 4
                    If lTemp = 805319936 Then
                        'GetJet4Version = "09.50" & " - " & "Access 2002 or 2003"
                        GetJet4Version = "Access 2002/2003"
                        Exit Function
                    End If
                ElseIf lTemp = 771766272 Then
                    ' Grab the next 4 bytes
                    CopyMem lTemp, bytData(lCtr + 1 + 4), 4
                    If lTemp = 805319936 Then
                        'GetJet4Version = "08.50" & " - " & "Access 2000"
                        GetJet4Version = "Access 2000"
                        Exit Function
                    End If
                End If
            Case Else
                ' Do nothing
        End Select
    Next lCtr
    
    ' Error - no match
    GetJet4Version = ""
End Function
Private Function GetJet3Version(bytData() As Byte) As String
    Dim lCtr As Long
    Dim bytCurValue As Byte
    Dim lTemp As Long
    
    'Loop Lthrough the bytes in the file
    For lCtr = 1 To UBound(bytData) - 24
        ' We are looking for
        '         07.53 Access 97 -> 48 55  46  53 51
        '         06.68 Access 95 -> 48 54  46  54 56
        '         2.0   Access 2.0 ->50  46  48
        '         1.0   Access 1.x (does not distinguish 1.0 and 1.1)-> 49 46 48
        
        bytCurValue = bytData(lCtr)
        
        Select Case bytCurValue
            Case 48 '"0"
                ' Grab the next 4 bytes
                CopyMem lTemp, bytData(lCtr + 1), 4
                If lTemp = 859123255 Then
                    'GetJet3Version = "07.53" & " - " & "Access 97"
                    GetJet3Version = "Access 97"
                    Exit Function
                ElseIf lTemp = 943074870 Then
                    'GetJet3Version = "06.68" & " - " & "Access 95"
                    GetJet3Version = "Access 95"
                    Exit Function
                Else
                    ' do nothing
                End If
            Case 50 '"2"
            '    If bytData(lCtr + 1) = 46 Then
            '        If bytData(lCtr + 2) = 48 Then
            '            'GetJet3Version = "2.0" & " -" & "Access 2"
            '            GetJet3Version = "Access 2"
            '            Exit Function
            '        End If
            '    End If
            Case 49 '"1"
            '    If bytData(lCtr + 1) = 46 Then
            '        If bytData(lCtr + 2) = 48 Then
            '            'GetJet3Version = "1.0" & " - " & "Access 1"
            '            GetJet3Version = "Access 1"
            '            Exit Function
            '        End If
            '    End If
            Case Else
                
        End Select
    Next lCtr
    
    ' Error - no match
    GetJet3Version = ""
End Function