Katherine said:
Fantastic. Thanks, that worked like a charm.
I've had a go at altering that function so that it will test whether the
user has entered information into two textboxes but its kicking up an error
(object does not support this property or method) so i assumei'm using the
wrong thing for the wrong job. Basically i have two text fields that are
mandatory, so i want to ensure that they have been completed before the
submit button is enabled.
Are these the only two textboxes on the UserForm?
If so, then you can alter the code like this
Private Function TextBoxesFilled() as Boolean
Dim oControl as Control
For Each oControl in Me.Controls
If TypeOf oControl is MSForms.TextBox Then
If Len(oControl.Text) = 0 Then
TextBoxesFilled = False
Exit Function
End If
End If
Next oControl
TextBoxesFilled = True
End Function
If only certain textboxes are mandatory, then you need to have a way of
identifying them. The approach I usually take for this is to put some text
(such as "mandatory") into the Tag property of the Textbox. The tag property
doesn't display on the form and is very useful for this kind of thing. With
the Tag property set for the mandatory textboxes, the code would now need to
be as follows.
Private Function TextBoxesFilled() as Boolean
Dim oControl as Control
For Each oControl in Me.Controls
If TypeOf oControl is MSForms.TextBox Then
If oControl.Tag = "mandatory" Then
If Len(oControl.Text) = 0 Then
TextBoxesFilled = False
Exit Function
End If
End If
End If
Next oControl
TextBoxesFilled = True
End Function
If you change your mind about which textboxes are mandatory, you don't need
to bother altering the code, you simply add or remove "mandatory" from the
tag property as appropriate.
Any clues? If you can help me out on this one Jonathan you're welcome to
my firstborn
