Validating and calculating parameters for the Party Summary Report | Newbie | | Join Date: Mar 2007
Posts: 1
| | |
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....
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Validating and calculating parameters for the Party Summary Report -
IF isdate(Me!MyValidDate1) and Me!MyValidDate1 = Dateadd("m",-1,Me!MyValidDate1) then
-
Me!MyValidDate2 = DateAdd("d",-1,Date())
-
end if
-
Something like this?
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,680
| | | re: Validating and calculating parameters for the Party Summary Report
Plagiarising shamelessly from Denburt's code, I just tweaked some details to match your requirement a little more closely. - 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
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Validating and calculating parameters for the Party Summary Report Quote:
Originally Posted by NeoPa Plagiarising shamelessly from Denburt's code, I just tweaked some details to match your requirement a little more closely. - 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: ;) -
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
-
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,680
| | | re: Validating and calculating parameters for the Party Summary Report
You won't want the End If AS WELL AS the continuation character (_) after the Then. You could use either one depending on style.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Validating and calculating parameters for the Party Summary Report
My appologies you are absolutely correct still on my first cup of mud... eyes half opened and didn't see the _ :)
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,680
| | | re: Validating and calculating parameters for the Party Summary Report
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.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,295 network members.
|