Private Function help

  • Thread starter Thread starter Chad
  • Start date Start date
C

Chad

Hello, Im using a function in my switchboard with two text boxes that
requires me to select dates. Its working fine but I want to have another
section with a differnt area on the same switchboard that will allow me to
choose only one date from a seperate text box. How would I fix the code below
so that it only requires me to have a date in a text box named
txtSupervisors? Thanks!

Private Function ValidDates() As Boolean

Dim strMsg As String

ValidDates = True

If IsDate(Me.txtStartDate) And IsDate(Me.txtEndDate) Then
If Me.txtStartDate > Me.txtEndDate Then
strMsg = "Start Date must be EQUAL TO or LESS THAN End Date."
End If
Else
strMsg = "Both Start and End Dates are Required for the Reports."
End If

If Len(strMsg) Then
MsgBox strMsg, vbOKOnly, "Date Entry Error"
ValidDates = False
End If

End Function
 
Hi Chad,
How many dates are needed to be checked?
Will there be Start date, End date and Supervisor date?
What rule is there about the Supervisor date? Can it be any date? Can it be
blank?

Jeanette Cunningham
 
I want to only check one text box named txtStartDate instead of two like in
the example. Thanks!
 
Chad,
try the following code, is this gentle enough for you?

If just checks that the user has chosen a date, and if they haven't, gives
them the message and sets ValidDates to false.

Private Function ValidDates() As Boolean
Dim strMsg As String

ValidDates = True

If IsNull(Me.txtStartDate) Then
strMsg = "You must choose a start date."
ElseIf Not IsDate(me.txtStartDate) then
strMsg = "You must choose a valid date."
End If

If Len(strMsg) Then
MsgBox strMsg, vbOKOnly, "Date Entry Error"
ValidDates = False
End If

End Function
 
Back
Top