Hi Guys & Gals,
I am in the process of creating a module to validate a MulitPage UserForm that is composed of, among other controls, multiple frames, each containing a TextBox and two OptionButtons. I need to identify those frames where the TextBox value is not null and neither of the OptionButtons have been selected. The module will pass as variables the TextBox value, OptionButton captions and Frame caption to another module that will create a UserForm with the invalid Frame/TextBox/OptionButtons sets for the user to correct.
The interim code listed below runs as a command button on a test UserForm. The MsgBox displays only the first of the OptionButton’s caption as Opt1 and Opt2. Can anyone tell me why and where I went awry?
Public WithEvents As MSforms.TextBox, Opt1 As String, Opt2 As String, vtxt As Long, vFrame As String, vTag As String
Private Sub CommandButton1_Click()
Dim pPage As Page, cCont As Control, vCont As MSforms.Control
'Dim Opt1 As String, Opt2 As String, vtxt As Long, vFrame As String, vTag As String
For Each pPage In Me.MultiPage1.Pages
For Each cCont In pPage.Controls
If TypeName(cCont) = "Frame" Then
For Each vCont In cCont.Controls
If TypeOf vCont Is MSforms.TextBox Then
If vCont.Value <> vbNullString Then
vtxt = vCont.Value
vFrame = cCont.Caption
Else
Exit For
End If
End If
If TypeOf vCont Is MSforms.OptionButton Then
If vCont.Value = False Then
Opt1 = vCont.Caption
Else
Exit For
End If
End If
If TypeOf vCont Is MSforms.OptionButton Then
If vCont.Value = False Then
Opt2 = vCont.Caption
End If
End If
Next vCont
End If
Next cCont
Next pPage
MsgBox vFrame & ", " & vtxt & ", " & Opt1 & ", " & Opt2
End Sub
Display More
Is there a more elegant way of accomplishing this? (Control Tags are already spoken for.)
Many Thanks,
John