date function

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Howdy All, I have an IF statement that I am about to put into around 15
forms. Rather than use the same code how can I alter this code so that the
'me.txtDate' is different for every form.

Sorry I've become brain dead and connot remember how to do this.

If me.txtDate < Now() Then
msgbox "This date is in the past and therefore cannot be saved"
End If
 
Why not just use the existing validation options for the control?

In the criteria you could put =>Date()

Then the user would be unable to make the entry incorrectly.

Of course, this assumes they are entering the item, and not viewing existing
records.
 
Your question is not clear. What do you mean by "me.txtDate is different for
every form?
Different Name
Different Value
Different Comparison
 
Sorry, 'me.txtDate' = the textbox name. These textboxes are named similar
names like txtInterviewDate, txtJoinDate, txtEndDate.
The values in these textboxes will all be different, however I want to
produce a message box (yes /no) when the user enters a date that is before
todays date.
 
In some cases I will want to give the user the right to enter the date
before todays date.
 
Ummmm - Again, why not use validation? If the date must match the rule,
then validation will do it.

Unless you want to let the user override the rule.
 
How about writing a little public function that you can call.

In the AfterUpdate property of the control(s), enter
=CheckDate()

'Untested AIRCODE follows
Public Function CheckDate()
Dim ctlAny As Control

Set ctlAny = Screen.ActiveControl

If IsDate(ctlAny.Value) then
If ctlAny.Value < Date Then
Msgbox "Date is in the past. Please check it."
End If
End if

Exit Function

CheckDate_Error:
If Err.Number = 2474 Then
Exit Function
Else
MsgBox "Error " & Err.Number & " (" & _
Err.Description & ") in procedure CheckDate"
End If

End Function
 
Back
Top