tnguyen315
MIS
Hello all, please help. I'm very appreciated.
On the form, I have 1 combo box with values list "Annual, Semi-Annual, Quarter" for users to select only in this list.
And 2 text boxes named "txtBeginDate" and "txtEndDate" to users to enter the date period. I would like if users select "Annual" in the combox box above, then enter date in "txtBeginDate" = "03/01/YYYY" and "txtEndDate" = "02/28/YYYY" (or either "02/29/YYYY" if available). I would like in the "lost focus" control or "after update" ...when users enter wrong date period, then message pop up and saying something like "Wrong date period, please re-enter!". Samething with Semi-Annual and Quarter" also.
The period cover:
Annual : "03/01/YYYY" - "02/28/YYYY" (or 02/29/YYYY)
Semi-Annual: "03/01/YYYY" - "08/31/YYYY"
"09/01/YYYY" - "02/28/YYYY" (or 02/29/YYYY)
Quarter: "03/01/YYYY" - "05/31/YYYY"
"06/01/YYYY" - "08/31/YYYY"
"09/01/YYYY" - "11/30/YYYY"
"12/01/YYYY" - "02/28/YYYY" (or 02/29/YYYY"
Right now, I can write something in the lost focus control to work:
Below is my code:
Private Sub txtBeginDate_LostFocus()
Dim strGetDate As String
strGetDate = Format$(Me.txtBeginDate, "MM/DD")
If me.cboPeriod = "Annual" then
If strGetDate <> "03/01" then
Msgbox "Wrong date period, please re-enter!"
me.txtBeginDate.SetFocus
Exit Sub
End If
ElseIf me.cboPeriod = "Semi-Annual" then
If (strGetDate <> "03/01") or (strGetDate <> "09/01")then
Msgbox "Wrong date period, please re-enter!"
me.txtBeginDate.SetFocus
Exit Sub
End If
ElseIf me.cboPeriod = "Quarter" then
If (strGetDate <> "03/01") or (strGetDate <> "06/01") or (strGetDate <> "09/01") or (strGetDate <> "12/01")
Msgbox "Wrong date period, please re-enter!"
me.txtBeginDate.SetFocus
Exit Sub
End If
End If
End Sub
I do the samething for "txtEndDate" but I have the problem is when the year has Feb 29, then it will also work Feb 28. So please help on this part, if the year has Feb 29, then when users enter "02/28/YYYY" it'll also need to pop up a message and saying wrong date. Please help. Thank you very much.
On the form, I have 1 combo box with values list "Annual, Semi-Annual, Quarter" for users to select only in this list.
And 2 text boxes named "txtBeginDate" and "txtEndDate" to users to enter the date period. I would like if users select "Annual" in the combox box above, then enter date in "txtBeginDate" = "03/01/YYYY" and "txtEndDate" = "02/28/YYYY" (or either "02/29/YYYY" if available). I would like in the "lost focus" control or "after update" ...when users enter wrong date period, then message pop up and saying something like "Wrong date period, please re-enter!". Samething with Semi-Annual and Quarter" also.
The period cover:
Annual : "03/01/YYYY" - "02/28/YYYY" (or 02/29/YYYY)
Semi-Annual: "03/01/YYYY" - "08/31/YYYY"
"09/01/YYYY" - "02/28/YYYY" (or 02/29/YYYY)
Quarter: "03/01/YYYY" - "05/31/YYYY"
"06/01/YYYY" - "08/31/YYYY"
"09/01/YYYY" - "11/30/YYYY"
"12/01/YYYY" - "02/28/YYYY" (or 02/29/YYYY"
Right now, I can write something in the lost focus control to work:
Below is my code:
Private Sub txtBeginDate_LostFocus()
Dim strGetDate As String
strGetDate = Format$(Me.txtBeginDate, "MM/DD")
If me.cboPeriod = "Annual" then
If strGetDate <> "03/01" then
Msgbox "Wrong date period, please re-enter!"
me.txtBeginDate.SetFocus
Exit Sub
End If
ElseIf me.cboPeriod = "Semi-Annual" then
If (strGetDate <> "03/01") or (strGetDate <> "09/01")then
Msgbox "Wrong date period, please re-enter!"
me.txtBeginDate.SetFocus
Exit Sub
End If
ElseIf me.cboPeriod = "Quarter" then
If (strGetDate <> "03/01") or (strGetDate <> "06/01") or (strGetDate <> "09/01") or (strGetDate <> "12/01")
Msgbox "Wrong date period, please re-enter!"
me.txtBeginDate.SetFocus
Exit Sub
End If
End If
End Sub
I do the samething for "txtEndDate" but I have the problem is when the year has Feb 29, then it will also work Feb 28. So please help on this part, if the year has Feb 29, then when users enter "02/28/YYYY" it'll also need to pop up a message and saying wrong date. Please help. Thank you very much.