MS-Access / Getting Started

Create the Client Application

The hard part is done - we just need to hook it up into a client application. Start by creating a new database called ClientApp.accdb. Create the AppVersion property in this database as follows:

  1. Click the Office menu and choose Manage; then click Database Properties.
  2. Choose the Custom tab in the Properties dialog box.
  3. Type AppVersion in the Name text box.
  4. Type 1.0 in the Value text box, and then click Add. Click OK to close the dialog box.

Next, create a new form called frmCheckVersion and add the following code to the Load event of the form.

Private Sub Form_Load()
    Dim obj As Access.Application
    Dim upd As Object

We're going to automate the versioning server to get an instance of the Updater class. To do this, we need to run code in this database. Launch a new instance of Access and set the AutomationSecurity property of the new instance to allow code to run:

    Set obj = New Access.Application
    obj.AutomationSecurity = 1

Next, open the versioning server and hide it. Change the path to the versioning server on your computer.

    obj.OpenCurrentDatabase "<PathTo>\VersioningServer.accdb"
    obj.Visible = False

Because the client application doesn't have a class module called Updater, we're using late binding to the Updater class in the versioning server. Remember that the server application has a function called GetUpdaterInstance to give us an instance of this class. Add the following code to get a late-bound instance of the Updater class and set the ApplicationDatabase property:

    ' get the object
    Set upd = obj.Run("GetUpdaterInstance")
    upd.ApplicationDatabase = CurrentDb.Name

Last, use the IsLatestVersion function in the class to determine whether the client is running the latest version. If it is not, call the StartUpdate method of the Updater class in the server application. If the client is running the latest version, we'll display the version number from the AppVersion property and close the frmCheckVersion form.

    If (Not upd.IsLatestVersion) Then
	' start the update - sets the timer interval of frmTimer
	upd.StartUpdate

	' close this database
	Application.Quit acQuitSaveNone
    Else
	MsgBox "You are running version: " & _
    CurrentDb.Containers("Databases").Documents("UserDefined").Properties("AppVersion")
	DoCmd.Close acForm, Me.Name
    End If
End Sub
[Previous] [Contents] [Next]