A
Ann
I'm having a problem with getting SetFocus to work and with 1/1/2008 being
recognized as later then 12/31/2007. I have listed the code below. (Sorry
this is so long).
It originally had a Cancel = True on the Event but I was asked to remove it.
The reason being if the txtBenefitPeriodEndDate is before the txt
BenefitPeriodBeginDate but it's the begin date that was entered incorrectly
then the user has to enter a date in the txtBenefitPeriodEndDate before it
will allow them to get back to the txtBenefitPeriodBeginDate.
The two sets of dates I have work together. They are:
txtBenefitPeriodStartDate
txtBenefitPeriodEndDate (must be later then txtBenefitPeriodStartDate)
txtHRAStartDate (must be later or equal to txtBenefitPeriodStartDate)
txtHRAEndDate (must be later then txtHRAStartDate and equal to the
txtBenefitPeriodEndDate)
Since they do work together I just want to remove the text from
txtBenefitEndDate and keep the cursor there because if it moves to
txtHRAStartDate then I get that message if I click into
txtBenefitPeriodStartDate.
Here is the code for txtBenefitPeriodEndDate and txtHRAStartDate:
Private Sub txtBenefitPeriodEndDate_Exit(ByVal Cancel As
MSForms.ReturnBoolean)
' 5.) Benefit Period End Date must be greater then 4.)
'Benefit Period Start Date.
If txtBenefitPeriodEndDate.Value < txtBenefitPeriodStartDate.Value Then
MsgBox "The Benefit Period End Date must be" _
& vbCrLf & "after the Benefit Period Start Date."
txtBenefitPeriodEndDate = Null
txtBenefitPeriodEndDate.SetFocus
End If
End Sub
Private Sub txtHRAStartDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
' 6.) HRA Start Date must be later or equal to 4.) Benefit Period Start Date
If txtHRAStartDate.Value < txtBenefitPeriodStartDate Then
MsgBox "The HRA Start Date must be later or" _
& vbCrLf & "equal to the Benefit Period Start Date"
txtHRAStartDate.Value = Null
txtHRAStartDate.SetFocus
End If
End Sub
I am just beginning to learn and am very confused why SetFocus doesn't seem
to work. It seems to work fine if I want it to go in a forward motion but if
I try to get it to stay where it is or go backwards it just doesn't work.
Also, the dates. It works if 01/01/2008 (txtBenefitPeriodEndDate) is before
01/02/2008 (txtBenefitPeriodStartDate) but not if 12/31/2007 is prior to
01/01/2008. Any help I can get is greatly appreciated. Thanks.
recognized as later then 12/31/2007. I have listed the code below. (Sorry
this is so long).
It originally had a Cancel = True on the Event but I was asked to remove it.
The reason being if the txtBenefitPeriodEndDate is before the txt
BenefitPeriodBeginDate but it's the begin date that was entered incorrectly
then the user has to enter a date in the txtBenefitPeriodEndDate before it
will allow them to get back to the txtBenefitPeriodBeginDate.
The two sets of dates I have work together. They are:
txtBenefitPeriodStartDate
txtBenefitPeriodEndDate (must be later then txtBenefitPeriodStartDate)
txtHRAStartDate (must be later or equal to txtBenefitPeriodStartDate)
txtHRAEndDate (must be later then txtHRAStartDate and equal to the
txtBenefitPeriodEndDate)
Since they do work together I just want to remove the text from
txtBenefitEndDate and keep the cursor there because if it moves to
txtHRAStartDate then I get that message if I click into
txtBenefitPeriodStartDate.
Here is the code for txtBenefitPeriodEndDate and txtHRAStartDate:
Private Sub txtBenefitPeriodEndDate_Exit(ByVal Cancel As
MSForms.ReturnBoolean)
' 5.) Benefit Period End Date must be greater then 4.)
'Benefit Period Start Date.
If txtBenefitPeriodEndDate.Value < txtBenefitPeriodStartDate.Value Then
MsgBox "The Benefit Period End Date must be" _
& vbCrLf & "after the Benefit Period Start Date."
txtBenefitPeriodEndDate = Null
txtBenefitPeriodEndDate.SetFocus
End If
End Sub
Private Sub txtHRAStartDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
' 6.) HRA Start Date must be later or equal to 4.) Benefit Period Start Date
If txtHRAStartDate.Value < txtBenefitPeriodStartDate Then
MsgBox "The HRA Start Date must be later or" _
& vbCrLf & "equal to the Benefit Period Start Date"
txtHRAStartDate.Value = Null
txtHRAStartDate.SetFocus
End If
End Sub
I am just beginning to learn and am very confused why SetFocus doesn't seem
to work. It seems to work fine if I want it to go in a forward motion but if
I try to get it to stay where it is or go backwards it just doesn't work.
Also, the dates. It works if 01/01/2008 (txtBenefitPeriodEndDate) is before
01/02/2008 (txtBenefitPeriodStartDate) but not if 12/31/2007 is prior to
01/01/2008. Any help I can get is greatly appreciated. Thanks.