Code to validate StartDate and EndDate

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

What is the code to do the following --

If txtEndDate < txtStartDate
txtEndDate = null
txtEndDate setfocus
End If

Also, what event should the code be in?

Thanks!

Mark
 
Mark said:
What is the code to do the following --

If txtEndDate < txtStartDate
txtEndDate = null
txtEndDate setfocus
End If

That. Only put a dot (.) between txtEndDate and setfocus.
Also, what event should the code be in?

I think it needs to be called both when enddate and startdate change.
Create AfterUpdate events for both controls, and call a common procedure
from them. The common procedure can be called catchDates and will
contain your code.
 
Mark,

If Me.txtEndDate < Me.txtStartDate
Msgbox "End Date cannot be earlier than Start Date"
Me.txtEndDate = null
Me.txtEndDate.SetFocus
End If

I have added a message box to alert the user as to what they are doing
wrong, and why their entry disappeared.

Regularly, a user would first enter start date, then end date (you can also
guide them that way by means of relative position and tab order). So, I
guess you could use the on change event of the end date textbox.

HTH,
Nikos
 
Back
Top