date function

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
 
R

Rick B

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.
 
K

Klatuu

Your question is not clear. What do you mean by "me.txtDate is different for
every form?
Different Name
Different Value
Different Comparison
 
C

Chris

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.
 
C

Chris

In some cases I will want to give the user the right to enter the date
before todays date.
 
R

Rick B

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.
 
J

John Spencer

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
 

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

Top