Protect an MS-Access Application with Quick License Manager

[You can watch a video version of this guide here]

Following is a step-by-step procedure to protect an MS-Access application. Note that the steps below assume you have a QLM License Server already setup.

1. Launch QLM

2. Create a product from the β€œDefine Product” tab or use the Demo 1.0 product if you are evaluating QLM.

3. Go to the "Protect your application tab":

  • Page 1: Select the product to protect and the License Server

  • Page 2: Select "VB6, VBA, ..."

  • Page 3: Leave the default settings or customize the look & feel if needed. By default, QLM will bind the license to the Computer Name. You can select the binding of your choice by setting the QlmLicenseBinding property located in the section "6. Qlm License Properties".

  • Page 4: Select the folder where your Access application is located and click Save

  • Page 5: Click Finish

4. In the folder where your MS-Access application is located, create a folder called 'Qlm' and copy the following files to the Qlm folder:

  • C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 4.0\QlmlicenseLib.dll

  • C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 4.0\QlmLicenseLib.tlb

  • C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 4.0\QlmCLRHost_x64.dll

  • C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 4.0\QlmCLRHost_x86.dll

  • C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 4.0\QlmLicenseWizard.exe

5. Open your MS-Access application and click Alt-F11 to launch the VBA Editor.

6. Click Tools / Add References and add the following references:

  • c:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.tlb

  • c:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscoree.tlb

  • QlmLicenseLib.tlb (this is not required but might be useful during development to enable the IDE to show all the properties and methods of the QLM classes)

8. Assuming your MS-Access application has a Form, add a Form_Open event as follows:

Private Sub Form_Open(Cancel As Integer)
    QlmCheckLicense   
End Sub

9. In the VBA editor, click Insert / Module and set the module name to CheckLicense.

10. Paste the following code in the CheckLicense module:

 Dim homeDir As String
 Dim binDir As String
 Dim lv As LicenseValidator
 Dim settingsFile As String
 
Function QlmCheckLicense() As Boolean
    '
    ' for debugging purposes / stepping through the code - remove the Stop when done.
    '
    Stop
    On Error GoTo PROC_ERR
 
    Set lv = New LicenseValidator
    homeDir = lv.GetHomeDir(CurrentProject.path)
    binDir = homeDir & "\Qlm"
 
    ' Update the filename below with the one that you generated via the Protect Your App Wizard   
    settingsFile = homeDir & "\Demo 1.0.lw.xml"

    lv.InitializeLicense homeDir,  settingsFile, binDir

    Dim needsActivation As Boolean
    Dim errorMsg As String
    Dim binding As ELicenseBinding
    binding = ELicenseBinding_ComputerName
    If lv.ValidateLicenseAtStartupByBinding(binding, needsActivation, errorMsg) = False Then

       If LaunchWizard = 4 Then
            ExitApp
       End If

       If lv.ValidateLicenseAtStartupByBinding(binding, needsActivation, errorMsg) = False Then
            ExitApp
       End If
    End If
   Exit Function

PROC_ERR:
   MsgBox "Error: (" & Err.Number & ") " & Err.Description, vbCritical
   Stop
   ExitApp
End Function
Private Sub ExitApp()
    ' Before shipping your app, uncomment the Close statement in the ExitApp Sub
    ' During development, you may want to comment it out to avoid getting locked out of your app
    'DoCmd.Quit
End Sub
Public Function LaunchWizard() As Long
    Dim args As String

    args = args & " /settings " & """" & settingsFile & """"
    args = args & " /computerID " & lv.fOSMachineName

    Dim exitCode As Long
    Dim wizardExe As String
    wizardExe = binDir & "\QlmLicenseWizard.exe"
    If Dir(wizardExe) = "" Then
        wizardExe = "C:\Program Files\Soraco\QuickLicenseMgr\QlmLicenseWizard.exe"
    End If

    exitCode = lv.LicenseObject.LaunchProcess(wizardExe, args, True, True)

    LaunchWizard = exitCode
End Function

11. In the VBA editor, click Insert "Class Module"

12. Set the Class Module Name to: LicenseValidator

13. Paste the content of the LicenseValidator.cls file (this file was generated by the Protect Your application wizard) into the LicenseValidator class module.

This completes the integration. The next time you open your MS-Access form, the Form_Open event should get triggered and perform the license validation.

To generate a license key for testing purposes:

  • Go to the Manage Keys tab.

  • Click "Create Activation Key"

  • Select the Product (Demo 1.0 for trials) and click OK.

  • Copy and Paste the generated Activation Key in the License Wizard launched when your MS-Access Application starts up and follow the steps in the wizard.

IMPORTANT NOTES:

  • During development, if a license is not valid, the MsAccess file will still open. When development is completed, uncomment the Close statement in the ExitApp Sub to make sure that your MsAccess file cannot be opened without a valid license key.

  • It is recommended to ship to your customer a compiled MsAccess file (ACCDE).

  • Finally, do not forget to password-protect your VBA code to protect it. To protect your VBA code:

    • In the VBA Editor, click Toos / "YourProject" Properties

    • Go to the Protection tab

    • Check "Lock project for viewing"

    • Enter a password / confirm password

    • Click OK

Restrictions

QLM does not support loading MsAccess apps from a network share using the late binding approach described in this article. The MsAccess files must be located in a local folder.

If you need to support hosting your MsAccess files on a network share, you will need to use the early binding approach and register the QlmLicenseLib.dll when deploying your application.

Last updated