Connecting Tech Pros Worldwide Help | Site Map

Validating and calculating parameters for the Party Summary Report

Newbie
 
Join Date: Mar 2007
Posts: 1
#1: Mar 22 '07
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's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#2: Mar 22 '07

re: Validating and calculating parameters for the Party Summary Report


Expand|Select|Wrap|Line Numbers
  1. IF isdate(Me!MyValidDate1) and Me!MyValidDate1 = Dateadd("m",-1,Me!MyValidDate1) then
  2. Me!MyValidDate2 = DateAdd("d",-1,Date())
  3. end if
  4.  
Something like this?
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,680
#3: Mar 23 '07

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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub MyValidDate1_AfterUpdate()
  2.   If IsDate(Me.MyValidDate1) _
  3.   And Me.MyValidDate1 < DateAdd("m", -1, Date) Then _
  4.     Me.MyValidDate2 = DateAdd("m", 1, Me.MyValidDate1) - 1
  5. End Sub
Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#4: Mar 23 '07

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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub MyValidDate1_AfterUpdate()
  2.   If IsDate(Me.MyValidDate1) _
  3.   And Me.MyValidDate1 < DateAdd("m", -1, Date) Then _
  4.     Me.MyValidDate2 = DateAdd("m", 1, Me.MyValidDate1) - 1
  5. End Sub


What he said: ;)
Expand|Select|Wrap|Line Numbers
  1. Private Sub MyValidDate1_AfterUpdate()
  2.   If IsDate(Me.MyValidDate1) _
  3.   And Me.MyValidDate1 < DateAdd("m", -1, Date) Then _
  4.     Me.MyValidDate2 = DateAdd("m", 1, Me.MyValidDate1) - 1
  5. End if
  6. End Sub
  7.  
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,680
#5: Mar 23 '07

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.
Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#6: Mar 23 '07

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 _ :)
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,680
#7: Mar 23 '07

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.
Reply