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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -