Dynamic userform help - Data Validation

J

James

I have a dynamic userform that has a multipage on it. Each page of the
multipage gets populated with labels, textboxes and comboboxes. I need to
know how to go about doing some data validation. ie. some boxes will have
just numbers, just text, text and numbers or date. I need to set an input
mask for each textbox or combo, and its not easy because the names of the
controls will change each time depending on options selected. I have set the
tag values for each as well so maybe i can use those for something. I dont
know of an event that fires when any textbox changes. Any help would be great
thanks.
 
P

Patrick Molloy

there's CHANGE as well as key press, key down and so on
double click the text box and it will take you to the default event. th
elist where you see 'change' will show what elese is available.
 
J

James

thanks for the reply but that is what i was trying to explain. it is a
dynamic userform, therefore there is just a form with 8 pages on a multipage
control. No textboxes or comboboxes. they get populated later based on
selections.

does anyone know how to write code that "writes code" so on creation of a
new texbox or combobox it places:

Sub Textbox(i)_Change()
validation_function
end sub

Would that work? Im not sure?
 
P

Patrick Molloy

here's a simple example to get you going....code is behind the userform...

thios simply creates 10 text boxes on the form. you vcan easily amend for
whetever you need ....

Option Explicit
Dim WithEvents ctTextBox As clsControl
Public ctrl As Control
Private Sub UserForm_Initialize()
Set ctTextBox = New clsControl
Add_Controls "Forms.Textbox.1", 10
End Sub
Private Sub Add_Controls(sType As String, count As Long)
Dim index As Long
Dim TP As Long
TP = 10
For index = 1 To count
Set ctrl = Me.Controls.Add("Forms.Textbox.1")
With ctrl
.Top = TP + ctrl.Height
.Left = 25
.text = "TextBox " & index
End With

ctrl.Top = TP
TP = TP + ctrl.Height

Next
End Sub
 

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