I didn't think of this

P

PaleRider

Hi again,

I have code that prevents the use of a form after a certain amount of days.
What I didn't consider is someone just changing the date on the computer.
Now, I have to figure out how to handle that otherwise it's a mute point.
The code I have in place so far has flaws that can be exploited. Is there a
way to allow someone limited use of database for a certain time frame, then
disable it after that?

Here's the code I have so far which allows use for 14 days, but as mentioned
before it can be exploited by just changing the system date:

Private Sub Form_Open(Cancel As Integer)
Dim myDate As Date
myDate = #6/2/2009#

If DateDiff("d", myDate, Date) >= 14 Then
MsgBox "Your 7 day evaluation for this database has expired."
Cancel = True
End If

End Sub

-PR
 
K

Klatuu

There is a fairly simple solution for your problem. You could use two user
defined database properties to control it. One property would be the
installed date. When the user first opens the database, check for the
existance of the property. If it is not found, then set it to the current
date, otherwise, compare the current date to installed date.

That does not handle someone resetting the system clock, but there is a
sneaky way to deal with that as well. Use another database property that
will be Last Opened Date. After a user opens the database and you complete
the comparisons above, check to see if the system date is prior to the Last
Opened Date. That will tell you if the user has set the clock back. Then in
the UnLoad event of the form, update the Last Opend date to the current date.
 
P

PaleRider

Klatuu,

That sounds like it would work, but since my last post I thought of
something different. I have code that allows the user to create a few
records, then in the OnCurrent event I test to see if the record limit has
been reached. If it has then I show a message and then set AllowAdditions =
false so that no new records can be created.

Then, in the OnLoad property I need a way to check the Main table again to
see if the record limit has been reached. If yes, then I need to set cancel
= true in the main form and not allow it to open. I need some help coding
the OnLoad part.

My OnCurrent code below is courtesy of posters in this forum:

Private Sub Form_Current()
If Me.NewRecord Then
If Me.Recordset.RecordCount >= 5 Then
MsgBox "You can only create 5 records in the demo."
Me.AllowAdditions = False
End If
Else
Me.AllowAdditions = True
End If
End Sub
 
P

PaleRider

Klatuu,

I found the code I need looking at other posts in this forum. Apart from a
few changes, I believe this code was written by you for someone else :)
Thanks a million Klatuu for your response and willingness to help. We really
do need you here!!

' Here's what I put in the OnOpen section:

Private Sub Form_Open(Cancel As Integer)
Dim mySQL As String
Dim myDB As DAO.Database
Dim mySet As DAO.Recordset
Dim numRecords As Integer

varSQL = "Select * from Main"

Set myDB = CurrentDb
Set mySet = myDB.OpenRecordset(varSQL)

If mySet.BOF = True Then
'there are no records in Main - so return 0
numRecords = 0
Else
mySet.MoveLast
numRecords = mySet.RecordCount
End If
End Sub


-PR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top