Hello all,
A requirement for a database I'm working on is that the date fields consist of the three constituent date parts - the day (dd), the month (mm) and the year (yyyy). I've written the following code to check the values entered in the day and month fields (below).
My problem is that there are numerous of these dates. I don't want to have to repeat the code every time I have a date field. I'd rewrite this code as a function that I can call when I need to but need some help with it. Any ideas if this can be done?
TIA,
----------------------------CODE------------------------------------
If (Me.txtmm = 1) Or (Me.txtmm = 3) Or (Me.txtmm = 5) Or (Me.txtmm = 7) _
Or (Me.txtmm = 8) Or (Me.txtmm = 10) Or (Me.txtmm = 12) Then
If (txtdd > 31) Or (txtdd < 1) Then
MsgBox ("Please check day."), vbOKOnly, "Error"
txtdd.SetFocus
End If
ElseIf (Me.txtmm = 4) Or (Me.txtmm = 6) Or (Me.txtmm = 9) Or (Me.txtmm = 11) Then
If (txtdd > 30) Or (txtdd < 1) Then
MsgBox ("Please check day."), vbOKOnly, "Error"
txtdd.SetFocus
End If
ElseIf (Me.txtmm = 2) Then
If (txtdd > 29) Or (txtdd < 1) Then
MsgBox ("Please check day."), vbOKOnly, "Error"
txtdd.SetFocus
End If
End If
A requirement for a database I'm working on is that the date fields consist of the three constituent date parts - the day (dd), the month (mm) and the year (yyyy). I've written the following code to check the values entered in the day and month fields (below).
My problem is that there are numerous of these dates. I don't want to have to repeat the code every time I have a date field. I'd rewrite this code as a function that I can call when I need to but need some help with it. Any ideas if this can be done?
TIA,
----------------------------CODE------------------------------------
If (Me.txtmm = 1) Or (Me.txtmm = 3) Or (Me.txtmm = 5) Or (Me.txtmm = 7) _
Or (Me.txtmm = 8) Or (Me.txtmm = 10) Or (Me.txtmm = 12) Then
If (txtdd > 31) Or (txtdd < 1) Then
MsgBox ("Please check day."), vbOKOnly, "Error"
txtdd.SetFocus
End If
ElseIf (Me.txtmm = 4) Or (Me.txtmm = 6) Or (Me.txtmm = 9) Or (Me.txtmm = 11) Then
If (txtdd > 30) Or (txtdd < 1) Then
MsgBox ("Please check day."), vbOKOnly, "Error"
txtdd.SetFocus
End If
ElseIf (Me.txtmm = 2) Then
If (txtdd > 29) Or (txtdd < 1) Then
MsgBox ("Please check day."), vbOKOnly, "Error"
txtdd.SetFocus
End If
End If