By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,390 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Set expiration date in MS access

P: 1
I want to set an expiration date in MS Access exacly in VBA on open form, beginning from actual Date to 30 days, or 1 year. i have this code :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. if date>= "#June 10th 2014#" then
  3.    msgbox("Sorry Evaluation Period Expired")
  4.    cancel = true
  5.    Exit sub
  6. end if
  7. End Sub
But i want to add 30 days from now,(actual date) and appear a message box that says: Sorry Evaluation Period Expired
Feb 14 '14 #1
Share this Question
Share on Google+
6 Replies


100+
P: 294
I'm confused. What date to you want to use? 1 year or 30 days?

"I want to add 30 days from now" .. So is the 1 year no longer relevant?

If I used your code and changed it to 30 days from now, I would write it like this:

Expand|Select|Wrap|Line Numbers
  1. Dim dt As Date
  2.  
  3. dt = [YourDateField]
  4.  
  5. If dt >= DateAdd("d", 30, Date) Then
  6. MsgBox("Sorry Evaluation Period Expired")
  7. End If
Feb 14 '14 #2

NeoPa
Expert Mod 15k+
P: 31,186
Kushtrim.

You have posted air-code. That is - code that is not compiled or workable or has ever been taken from your code. This is simply stuiff you've typed into the post.

Please don't do that is it is soooo wasteful of the time and effort of our experts. Take the trouble to test it properly first before posting it in here.

See Before Posting (VBA or SQL) Code for why this is not acceptable.
Feb 15 '14 #3

100+
P: 547
i use a "currentdate" textbox on the startup form and then use this code in the load event.
Expand|Select|Wrap|Line Numbers
  1. If Me.CurrentDate >= DateAdd("d", 30, Date) Then
  2. MsgBox "This program needs to be reinstalled as it has expired."
  3. DoCmd.Quit
Ensure that this code is ONLY added to a COPY of your original application, or you will never open it again!!!!
Feb 18 '14 #4

NeoPa
Expert Mod 15k+
P: 31,186
You'd typically want a value that's stored somewhere Neels. I doubt you're suggesting CurrentDate should be stored within the design of the form, yet otherwise your suggestion makes little sense.

The value would need to reflect the release date. Date() already gives you the current date. It's possible to store the release date in a table, but that would be so easy to manipulate unless it were encrypted. An alternative to storing it in the database that many people like, is to store it somewhere in the Windows Registry. This option makes finding it less straightforward for someone trying to circumvent the process. There's no reason why this, too, shouoldn't be encrypted.

Thus, the code for something like this (in very general terms) might be :
Expand|Select|Wrap|Line Numbers
  1. If DateAdd("m", 3, GetReleaseFromReg()) < Date() Then
  2.     Call MsgBox(Prompt:="License has expired.  Please contact ... for renewal" _
  3.               , Buttons:=vbOKOnly Or vbInformation _
  4.               , Title:=CurrentProject.Name)
  5.     Call Application.Quit
  6. End If
GetReleaseFromReg() would be a function that returns the release date.

NB. The comparison must be Less Than Date() related - Not Greater Than.
Feb 19 '14 #5

100+
P: 547
Thx Neopa that makes absolutely sense. Sorry i did not think properly. I usually "hardcode" the expirydate into vba when compiling to accde, but your method seems the right way. How would you use this "GetReleaseFromReg()" and get the current date copied into the registry to read it from? (i suppose that is classified info?)
Feb 19 '14 #6

NeoPa
Expert Mod 15k+
P: 31,186
Indeed not, but it is the topic of a separate question.

Feel free to post it and LMK when it's been done and I'll dig out some info for you. It makes sense for something like that not to be hidden away in another thread.

NB. It does use an OS feature (so not found in standard libraries) unless you go with the very basic approach. I'll cover it more fully in the answer when you post the question. Hopefully it'll make better sense there ;-)
Feb 19 '14 #7

Post your reply

Sign in to post your reply or Sign up for a free account.