Locking a database after a date
What I do is create a function in a module which takes care of things like this. I then call the function when the initial form opens.
For example, the function might be like this:
Public Function retReachedEndingDate() as boolean
retReachedEndingDate = False 'first assume it to be ok
Dim LookupEndDate as date
LookupEndDate = Dlookup("[EndDate]","tblEndingDate") 'The table: tblEndingDate would have 1 field (called: EndDate or whatever you want to call it.) It would be the date you want to shut off the program. (only enter in 1 record! If you update it, overwrite the existing record.)
If EndDate > Date() then
retReachedEndingDate = true
retReachedEndingDate = False
Then in the OnOpen event of my main background form (the form which only opens once when the mdb opens - hopefully you have a "background" type of form which then opens your other forms. See code bank for more info on this. It doesn't hurt to have it run several times if the form opens closes and opens again, etc... Anyway, it would be the form which is set to load on startup under Tools. Put this code in the In the OnLoad event of this form (look at the properties of the form.) Double-Click on the black area outside the details section to quickly see properties of the form:
if retReachedEndingDate = true then
msgbox "You have reached the time-limit to use this program. Contact...." (or show pop up form mentioned below).
You could also put the function itself in the main form. I prefer to keep in the module section simply because I can then easily access it from any form.
I'm assuming you'll have some way to activate the form for the user? My thought would be a simple form you implement which has the EndDate field on it (unbound with the default set to the date you want it to be.) Make the field locked = true and enabled = false (so they can't change it). Make a button which writes this to the EndDate field and then send them the form to import. OR you could also have a table which has 2 fields, VersionNum, EndDate. You could then get fancy and populate this table with different VersionNums (ie. 32ST44599T1) and a Date for each version. If you do the code right when designing the form, then in the future, you simply have them open the form and enter the new version number which will then write the corresponding Date to the EndDate field.
There are many different ways. This is one of the more simplier ones. I'm assuming that you'd hide the LookupEndDate Table (and the VersioningTable if you're going that way) and make it an mde file so they can't see your code (but give them the mdb as a courtesy copy - just make a "Your advertisement form" as the main form which shows and doesn't allow them to get behind the scenes (unless they hire an actual dba who would know how.)
I usually do something like this for versioning where I'll update a field to display the next version number (ie. the current date formatted in a version-type way.)
Last edited by pkstormy; 08-26-09 at 00:32.
Expert Database Programming
MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)