I want to create a module to restrict any textbox input, how to do it with follow example (not work)?
Please Login or Register to view this content.
I want to create a module to restrict any textbox input, how to do it with follow example (not work)?
Please Login or Register to view this content.
You might use code like this. Note that the code must put a "%" as the rightmost character of the text box in the Initialize event.
Please Login or Register to view this content.
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
Another way would be to put the "%" in a label right next to the text box and use only the KeyPress code above.
Thanks you for your reference, but I have more textbox with various input format. Can I set the modules for them like:
module A for integer input only
module B for decimal input only
module C for percentage% input only
module D for text input only
module E for date input only
with checking and Msgbox?
You could do that with a Class Module. (Date input would be a challenge, most people find that three combo boxes is a better user interface than a text box.)
About C, I would use a text box with a label rather than requiring the text box entry to end in "%".
Let me put something together and get back to you.
I used to follow code for date textbox input check. I have study how to use anyTextBox_KeyPress(ByVal KeyAscii) to restrict input content, have you any idea?
Please Login or Register to view this content.
I think you might like this.
This uses a custom class, clsTextBox. Every clsTextBox has a DataType
DataTypes can be
Number, Real, Integer, Letters, Alphanumeric and can be further modified as "Postitive Integer" "Upper Case Letters" "Non-Alphanumeric" "Non-Negative Real"
"Percentage" and "Date" are also possible.
If the user goes into a textBox that is type "Date" three combo boxes will be superimposed over the text box, the user selects the month,day and year from those combo boxes.
"Percentage" can also be modified with "integer" "real" "positive" "non-negative" etc. But a text box that is dataType "percentage" must end with a "%", even when empty, even at the start.
I much much prefer putting a label with "%" next to the data entry text box, with a numeric data type, rather than including the "%" in the text boxes value.
Other than the Date combo boxes
DataValidation is all controled from the IsValid UDF that is in the user form's code module.
You can add other data types as you wish. There is no need to change any of the code in the clsTextBox module.
The code in clsTextBox is mostly just passing properies through the class to the underlying text box and passing events
The bulk of the user form's code is the drivers for the Date combo boxes.Please Login or Register to view this content.
In the Userform_Intialize event, you notice that first all the text boxes are assigned to clsTextBox objects which are put into the TextBoxes collection. Then the data type for those text boxes are assigned.
The AnyTextBox_KeyPress event handles data entry, the _KeyDown event handles the Delete Key, _KeyUp and _MouseUp are used for the special handling needed by Percent and Date text boxes.Please Login or Register to view this content.
Thanks for your help, I will test and study your code in order to improve my project.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks