Some fields required question
I use the following code which loops through all fields on my user form,
searching for any text box that does not contain data.
Question: How can i modify this code such that only some of the fields
are
searched for missing data, rather than all. Reason: on my user form, 40
of
the 60 text boxes are required entry, and i want to make sure those fields
contain data.
Dim ctrl as Object
for each ctrl in Userform1.Controls
if typeof ctrl is msforms.combobox then
if ctrl.Value = "" then
msgbox "Missing Data in " & ctrl.Name
exit sub
end if
end if
Next
The body of your message says you have TextBoxes, but your code says
ComboBoxes. Either way... if the names for the controls that must be filled
in are unique in some way from the names for the controls that can be empty,
then you can modify your 2nd IF statement like this...
If ctrl.Value = "" And ctrl.Name Like "*uniquenamepart*" Then
If you unique name part come at the beginning or end of the name, you can
omit the asterisk at that end in the Like pattern string. If your naming
convention is not that structured, you can place the same text string in the
Tag property of those controls that must be filled in and then test for it
in the 2nd IF statement. For example, let's say that you put XX in each Tag
property for the controls that must have something filled in them; then your
2nd IF statement would look like this....
If ctrl.Value = "" And ctrl.Tag = "XX" Then
Rick
|