Number validation in Textbox using UserForm

C

Chris

Hi, I have a userform with 3 pages using MultiPage control
Each page has several textboxes where the user have to input numbers.

I wanted to make sure the user inputs numbers so I tried two methods.
Basically when the user inputs a non-numeric value, I wanted to set the
focus back to the textbox and prompt the user with a MsgBox

1. Using textBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
When the user inputs a non-numeric to the textbox, I set the Cancel
variable to true, forcing the control to be back to the textbox. It
works pretty good except when the user clicks on the other pages in
MultiPage instead of other textboxes in the same page.
If the user inputs a non-numeric value in the textbox and click on the
other pages, MsgBox doesn't pop up until the user decides to come back
to the page containing the errorsome textbox.
Also, when the user clicks on the "Cancel" button (Which calls Unload
Me), MsgBox pops up before the UserForm closes.

2. Using textBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
It works pretty good in a sense that the focus comes back to the
textbox even when the user clicks on the next page.
However, when that happens, MsgBox pops up twice.
Also, it won't even allow the user to click on "Cancel" button if the
user doesn't correct the non-numeric textbox.

How do I get around this problem?
 
T

Tom Ogilvy

Perhaps use the change event and check every keystroke. Don't allow non
numeric input.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top