Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba userform validation question

Status
Not open for further replies.

taupirho

Programmer
Jun 25, 2002
680
GB
Hi, I have two date picker controls on y userform, a start date and an end date. I want to ensure that the user cannot leave the startdate if its > the end date. I tried the following code in the control exit event but it didn't work, although I got the error message appearing the cursor just jumped to the next item and did not stay in the startdate item. What am I doing wrong?

if stardate > enddate then
msgbox(&quot;start date must be <= enddate&quot;)
startdate.setfocus
end if
 
change startdate.setfocus to cancel = true should do it
 
Thanks rivethead, your suggestion seemed to work. Code is now fine if I TAB out the startdate field but what about if I simply click on another field. How do I trap that. In VB i'd use lostfocus event I guess but VBA doesn't seem to have that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top