vba - Taking user back to specific textbox -


i have little routine checks time input... ie if user enters "8", change 08:00 etc etc... works great.

now thought i'll smart , make sure user enters max of 4 number , if not, msgbox pops up. far easy enough how on earth take him textbox can correct entry ? tried .setfocus nothing happens ?? ideas ?

private sub zb_exit(byval cancel msforms.returnboolean)    if len(zb) = 2     zb = zb & ":00"    elseif len(zb) = 1     zb = "0" & zb & ":00"    elseif len(zb) = 4     zb = left(zb, 2) & ":" & right(zb, 2)    elseif len(zb) = 3     zb = left(zb, 1) & ":" & right(zb, 2)    elseif len(zb) > 4     msgbox "what trying ???"     zb.setfocus    else    end if end sub 

santosh's suggestion great limiting characters allowed in textbox. alone may resolve problem. here answer others may not able use character limit readily can in example.

to return focus textbox zb, this:

    cancel = true     zb.value = vbnullstring     zb.setfocus 

the cancel = true part you're missing. cancels out exit event, force textbox value blank, , .setfocus.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -