Connecting Tech Pros Worldwide Forums | Help | Site Map

Code to validate StartDate and EndDate

Mark
Guest
 
Posts: n/a
#1: Nov 12 '05
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



Bas Cost Budde
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Code to validate StartDate and EndDate


Mark wrote:
[color=blue]
> What is the code to do the following --
>
> If txtEndDate < txtStartDate
> txtEndDate = null
> txtEndDate setfocus
> End If[/color]

That. Only put a dot (.) between txtEndDate and setfocus.
[color=blue]
> Also, what event should the code be in?[/color]

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.
--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

Nikos Yannacopoulos
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Code to validate StartDate and EndDate


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

"Mark" <mmorrow@earthlink.net> wrote in message
news:Ry7Ub.10151$GO6.6205@newsread3.news.atl.earth link.net...[color=blue]
> 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
>
>[/color]


Closed Thread