Restricting the Number of Times an Application is Launched
Instead of limiting an application by expiration date, you may restrict its overall usage by the number of times it is used. This gives users the flexibility to use the application as they need without a time limit as such. This scenario also has a drawback: Users who figure out what's happening might just launch the application and leave it open. You might work around this drawback by detecting idle time in the database and shutting it down after a period of time.
To track the number of times the application is launched, we're going to use a table. Depending on the amount of detail you wanted to display, there are a number of ways you could create the table. You could simply create a table that contains one field with one record that is incremented each time the database opens. We want to see a little more detail though so we're going to create a table that tracks the usage of the database. Start by creating a new table called USysUsageInfo. Add the fields shown in the following table.
Field Name Data Type (Size) ID AutoNumber UsageDate Date/Time UserName Text (255
Next, create a form called USysFrmUsageInfo and add the following code to the Load event of the form:
Private Const MAX_USAGE As Long = 10 Private Sub Form_Load() ' update the usage information Dim rs As DAO.Recordset Set rs = CurrentDb().OpenRecordset("USysUsageInfo") If (rs.RecordCount = MAX_USAGE) Then ' user has already reached the maximum MsgBox "You have reached your limit of " & MAX_USAGE & _ " uses of this application. Please contact us for a full version.", vbExclamation, _ "TRIAL VERSION" ' quit Application.Quit Else ' add a record to the usage table rs.AddNew rs!UsageDate = Now() rs!UserName = Environ("USERNAME") rs.Update End If ' close the form DoCmd.Close acForm, Me.Name End Sub
In this code, when the maximum number of usages is reached, we display a message to the user and quit the application. Until this value is reached we add a record to the USysUsageInfo table. Because we don't need the form hanging around, we close it when we're done.
To test this code, create a new autoexec macro with an OpenForm action that opens this form. Open the application ten times. On the eleventh attempt to open the application, you should see the warning that you've exceeded the number of times it can be used.
In this tutorial:
- Deployment
- Creating an Automated Build
- Design the Form
- Retrieving Information from the Source Database
- Building the Application
- Creating the Target Database
- Set Build Properties on the Target Database
- Setting Build Properties on the Source Database
- Deleting Data from Tables
- Calculating the Version Number
- Handling Application Dependencies
- Updating References
- Testing Reference Fix-Up
- Late Binding
- Licensing Your Applications
- Number of Records
- Restricting the Number of Times an Application is Launched
- Registering an Application
- Creating a Registration Web Service
- Validate the Registration Using the Web Service
- Miscellaneous Deployment Scenarios
- Create the Client Application
- Testing the Versioning Server
- Re-Linking Tables Automatically
- Programmatically Creating DSNs
- Creating a User DSN
- Ensuring an Application Runs Locally