N
NZ VBA Developer
I have a textbox on a userform that needs to be validated to ensure that the
value entered is numeric and that exactly 8 numbers have been entered, and
then format the value appropriately (NZ IRD Number: nn-nnn-nnn). I've written
a function to do the validation and formatting that is called on the Exit
event for the textbox, and it works fine except for one small problem: I
can't get focus to stay in the textbox if the validation fails.
I see in the VBA help that the syntax for Exit events is:
"Private Sub object_Exit( ByVal Cancel As MSForms.ReturnBoolean)"
and there is a note that says:
"To prevent the control from losing focus, assign True to the Cancel
argument of the Exit event."
However, I can't work out the syntax for actually assigning True to the
Cancel argument. The VBA compiler throws an error no matter what I try. Any
suggestions?
value entered is numeric and that exactly 8 numbers have been entered, and
then format the value appropriately (NZ IRD Number: nn-nnn-nnn). I've written
a function to do the validation and formatting that is called on the Exit
event for the textbox, and it works fine except for one small problem: I
can't get focus to stay in the textbox if the validation fails.
I see in the VBA help that the syntax for Exit events is:
"Private Sub object_Exit( ByVal Cancel As MSForms.ReturnBoolean)"
and there is a note that says:
"To prevent the control from losing focus, assign True to the Cancel
argument of the Exit event."
However, I can't work out the syntax for actually assigning True to the
Cancel argument. The VBA compiler throws an error no matter what I try. Any
suggestions?