Validation of Data


Posted by Robert Dorr on October 19, 2001 11:18 PM

I am designing a User Form.
I have a macro, at the start, which resets all the allowable user entries to blank.
The user entry cells in the tables in the form are validated to accept whole numbers between various ranges. The validation works fine providing the user enters something.

However if the user chooses to "TAB" trough the entry (and therefore leave it blank) the validation allows this, however I want to force a user entry.

I have ticked and unticked the "allow blanks" and read the "Help", but I cannot understand the function of the allow blanks as it seems to do nothing!

How do I force the user to enter a character rather than "TAB"?

Thanks & regards....... Robert

Posted by Jonathan on October 20, 2001 8:46 PM

You will of course expand on this idea to check for exactly what you want, but this prevents exiting the textbox control until SOMETHING is entered:


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If TextBox1.Text = "" Then
Cancel = True
End If

End Sub



Posted by Jonathan on October 20, 2001 8:49 PM

Let me add, Robert, that you can get to the 'stub' of this 'event-handler' by double-clicking the control (in this case a textbox control) while in Design mode; and then search the upper right drop down box in the code window for the 'Exit' event.

HTH

If TextBox1.Text = "" Then Cancel = True End If