Navigation:  Articles > Jul-1997 >

Tip: Wrap API Calls So They'll Work in All Versions of Access

Previous pageReturn to chapter overviewNext page

We are good at Access and Excel Programming and UpgradesLoad Basecamp Backup XML to Access or SQLServerThe Smart Access PDFs and DownloadsThe Toolbox - Access KBData Mining Tool In AccessThe Access WorkbenchThese are the products and services that we sell 

Jeff Kryzer

 

When I wrote a database that needed to exist in versions 2.0, 95, and 97, I wrote it to the least common denominator (Access 2.0).

In order to reduce bugs and ease the conversion from Access 2.0 to 95 and 97, I write my functions a certain way when they make API calls. For each function, I create a wrapper function that first checks the version of Access, then calls a different function depending on which version is being used, like this:

 

Function GetFileName (ByVal hWnd As Long) As String

    Dim varVersion As Variant

    varVersion = SysCmd(SYSCMD_ACCESSVER)

    Select Case varVersion

       Case 2

           GetFileName = GetFileName16(CInt(hWnd))

       Case >= 7

            GetFileName = GetFileName32(hWnd)

   End Select

End Function

 

 

 

Now, in any form I can just call the GetFileName() function and I don't have to worry about which version of Access I'm using. The window handle is passed in as a Long and then converted to an Integer only if I know I'm in Access 2.0. If I have to make a change to any part of the database, I make it in the version 2.0 copy, then convert the database to 95 and 97. No code change is necessary! Also, Access 2.0 doesn't seem to care whether I have 32-bit declarations in the module (as long as they're never called) and Access 95/97 doesn't care if I have 16-bit declarations in the module, so all the versions are happy!