• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Class Module for Text Boxes?

Gregg Wolin

Member
I’m trying to develop a userform to handle the data entry for model and my research tells me that I should use a class module(s) to handle the formatting of the data entered into various userform text boxes. Each text box is linked via Control Source to a named range in the workbook so that any assumption changed on the worksheet would show up on the userform next time it was opened and vice versa.



The issue I’m having is the text boxes need to be formatted as currency, percentages, text run numbers and dates. It appears that using a class module would alleviate the need To create code for each individual text box however all the examples I have seen require the identification by name (In the class module) of all text boxes on the form.

It seems like I should be able to create a class module for each data “type”.

My question: is there a way to use one of the properties of each text box as (for lack of a better term) the “trigger”. In other words, if the name of a text box includes the letters PCT, the class module would identify such a box and format it as a percentage?
 
Short answer: yes.

You can either create a class for each "type", have a collection for each class, and assign the textboxes based on their name (or another property such as Tag), or just use one class the formats based on the type.
 
Short answer: yes.

You can either create a class for each "type", have a collection for each class, and assign the textboxes based on their name (or another property such as Tag), or just use one class the formats based on the type.
Example code? None of the examples I have found include such functionality.
 
To be honest, I don't think you'll have a lot of luck with formatting using a class, since the most appropriate events (exit, before/after_update) are not exposed when using a WithEvents variable. There is an add-in you can get that uses some API calls to simulate the necessary events, but unless you need dynamic controls, it's simpler to just code each control to call a formatting routine in the relevant event.
 
Gregg
Unless it is critical i would accept the default number format and make sure it is clear using a Text Box adjacent to the Input Box that the value is a % etc
 
Back
Top