excel vba - Setting the cursor in a userform after invalid data entered -


i using following code (in excel 2013 windows 8.1):

private sub txtdatebox_exit(byval cancel msforms.returnboolean)     if isdate(txtdatebox.value) = false         msgbox "enter valid date, such jan 23, 2015"         txtdatebox.setfocus    end if end sub 

if enter invalid date msgbox pops when sub exited cursor has moved next textbox on userform. how can cursor believe me want go txtdatebox user enter valid date? codes work fine, cursor i'm having trouble with.

same thing happens when user puts invalid data 'bin' text box i.e. cursor jumps next textbox (when function returns "no") instead of ask cursor 'setfocus".

private sub txtbin1_exit(byval cancel msforms.returnboolean)     isitabin (val(txtbin1))     if binnumfound = "no"          msgbox "bin not found, please re-enter"         txtbin1.setfocus     end if end sub 

thanks in advance help.

if write in cancel = true, prevents cursor leaving textbox


Popular posts from this blog