Is it possible to create an ms access project which will run for a fixed period of time, after which the application will give a message "Validity Date has expired".If it is possible then please help me in writing the code.
Creating an ms access project which will run for 1 month only
Collapse
X
-
You have not indicated your specific circumstances, so I'll just generalize. I'm assuming that you have a Main Form that you work off of. Set the Form's Timer Interval to 30000 (30 seconds), and place the following code in the Timer() Event of the Form. Every 30 Seconds, the code will check the Current Date against 5/1/2010. If it is May 1, 2010 or greater the User will be notified that the Validity Date has expired, then the Database will immediately Close without Saving any pending Updates.
P.S. - Obviously you can substitute your own Date in the Constant as well as a different Timer Interval. My initial idea was to execute the code when the Database Opens, but it is conceivable that a User can Open the DB prior to the Validity Date and leave it Open past the Validity Date, which would cause problems.
Code:Private Sub Form_Timer() Const conDATE_TO_EXPIRE As Date = #5/1/2010# If Date >= conDATE_TO_EXPIRE Then MsgBox "Validity Date has expired", vbCritical, "Date expired" DoCmd.Quit acQuitSaveNone End If End Sub -
Is it possible? Yes. But Access isn't really known for its robust security and a determined user could probably get in anyway. Here is my stab at it:
1. First, make a copy of your database to work with. It would be unwise to block yourself out of your own work.Code:Option Compare Database Option Explicit Function CheckDate() If Now() > #3/31/2010# Then MsgBox "Validity date has expired." DoCmd.Quit acQuitSaveNone End If End Function Function SetBypassKey(BypassValue As Boolean) Const conPropNotFound As Integer = 3270 On Error GoTo createProp CurrentDb.Properties("AllowByPassKey") = BypassValue Exit Function createProp: If Err = conPropNotFound Then Dim Bypass As Property Set Bypass = CurrentDb.CreateProperty("AllowByPassKey", dbBoolean, False) CurrentDb.Properties.Append Bypass Resume Next End If End Function
2. Create a macro named autoexec. In it, put the RunCode action and put CheckDate() in the arguments. If your database is code heavy, calling it at the beginning of important pieces of code will make it harder to get around as well.
3. From the immediate window, type SetBypassKey False. You'll only have to do this once for the database. This makes it so you can't hold down Shift while opening the database to skip the autoexec macro.
4. Convert the database to .accde / .mde so no one can see or modify your code.
That takes care of all the ways in I can think of, but like I said... I make no guarantees as to this being ironclad.Comment
Comment