Private Function help

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
 
J

Jeanette Cunningham

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
 
C

Chad

I want to only check one text box named txtStartDate instead of two like in
the example. Thanks!
 
J

Jeanette Cunningham

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top