Validating and calculating parameters for the Party Summary Report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kerrysiddons
    New Member
    • Mar 2007
    • 1

    Validating and calculating parameters for the Party Summary Report

    I need to use VBA to validate that the first date parameter has been entered, is a valid date, and is at least a calendar month prior to today’s date. Then to Calculate the second date automatically, to be a month (minus one day) after the first date and show this on the form with the first date. (The user will thus only enter the first date, and both dates will be before today).
    I really dont have a clue where to start, can anybody give me any tips please? I am using Access....
  • Denburt
    Recognized Expert Top Contributor
    • Mar 2007
    • 1356

    #2
    Code:
    IF isdate(Me!MyValidDate1) and Me!MyValidDate1 = Dateadd("m",-1,Me!MyValidDate1) then
    Me!MyValidDate2 = DateAdd("d",-1,Date())
    end if
    Something like this?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      Plagiarising shamelessly from Denburt's code, I just tweaked some details to match your requirement a little more closely.
      Code:
      Private Sub MyValidDate1_AfterUpdate()
        If IsDate(Me.MyValidDate1) _
        And Me.MyValidDate1 < DateAdd("m", -1, Date) Then _
          Me.MyValidDate2 = DateAdd("m", 1, Me.MyValidDate1) - 1
      End Sub

      Comment

      • Denburt
        Recognized Expert Top Contributor
        • Mar 2007
        • 1356

        #4
        Originally posted by NeoPa
        Plagiarising shamelessly from Denburt's code, I just tweaked some details to match your requirement a little more closely.
        Code:
        Private Sub MyValidDate1_AfterUpdate()
          If IsDate(Me.MyValidDate1) _
          And Me.MyValidDate1 < DateAdd("m", -1, Date) Then _
            Me.MyValidDate2 = DateAdd("m", 1, Me.MyValidDate1) - 1
        End Sub

        What he said: ;)
        Code:
        Private Sub MyValidDate1_AfterUpdate()
          If IsDate(Me.MyValidDate1) _
          And Me.MyValidDate1 < DateAdd("m", -1, Date) Then _
            Me.MyValidDate2 = DateAdd("m", 1, Me.MyValidDate1) - 1
        End if
        End Sub

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          You won't want the End If AS WELL AS the continuation character (_) after the Then. You could use either one depending on style.

          Comment

          • Denburt
            Recognized Expert Top Contributor
            • Mar 2007
            • 1356

            #6
            My appologies you are absolutely correct still on my first cup of mud... eyes half opened and didn't see the _ :)

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              I'm always pleased if someone's checking over my contributions. I've had others stop me letting bad ones slip through before, so I know the value of it. Appology not required.

              Comment

              Working...