Set expiration date in MS access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kushtrim12
    New Member
    • Feb 2014
    • 1

    Set expiration date in MS access

    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 :
    Code:
    Private Sub Form_Open(Cancel As Integer)
    if date>= "#June 10th 2014#" then
       msgbox("Sorry Evaluation Period Expired")
       cancel = true
       Exit sub
    end if
    End Sub
    But i want to add 30 days from now,(actual date) and appear a message box that says: Sorry Evaluation Period Expired
    Last edited by Rabbit; Feb 14 '14, 04:33 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • mcupito
    Contributor
    • Aug 2013
    • 294

    #2
    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:

    Code:
    Dim dt As Date
    
    dt = [YourDateField]
    
    If dt >= DateAdd("d", 30, Date) Then
    MsgBox("Sorry Evaluation Period Expired")
    End If
    Last edited by mcupito; Feb 14 '14, 09:20 PM. Reason: Typo!

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32654

      #3
      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.

      Comment

      • neelsfer
        Contributor
        • Oct 2010
        • 547

        #4
        i use a "currentdat e" textbox on the startup form and then use this code in the load event.
        Code:
        If Me.CurrentDate >= DateAdd("d", 30, Date) Then
        MsgBox "This program needs to be reinstalled as it has expired."
        DoCmd.Quit
        Ensure that this code is ONLY added to a COPY of your original application, or you will never open it again!!!!

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32654

          #5
          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 :
          Code:
          If DateAdd("m", 3, GetReleaseFromReg()) < Date() Then
              Call MsgBox(Prompt:="License has expired.  Please contact ... for renewal" _
                        , Buttons:=vbOKOnly Or vbInformation _
                        , Title:=CurrentProject.Name)
              Call Application.Quit
          End If
          GetReleaseFromR eg() would be a function that returns the release date.

          NB. The comparison must be Less Than Date() related - Not Greater Than.

          Comment

          • neelsfer
            Contributor
            • Oct 2010
            • 547

            #6
            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 "GetReleaseFrom Reg()" and get the current date copied into the registry to read it from? (i suppose that is classified info?)

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32654

              #7
              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 ;-)

              Comment

              Working...