
Opening userforms from other userforms
You could put the name of the corresponding UserForm you want to call in the
Tag property of each optionbutton.
Then loop thru each UserForm to see which name matches the tag
(unfortunately, you have to load them before you can loop thru them):
Private Sub CommandButton1_Click()
Dim myOption As Control
Dim myTag As String
Dim i As Integer
For Each myOption In grpInput.Controls
If myOption.Value = True Then
myTag = myOption.Tag
Exit For
End If
Next myOption
Load UserForm2
Load UserForm3
For i = 0 To UserForms.Count - 1
If UserForms(i).Name = myTag Then
Me.Hide
UserForms(i).Show
Me.Show
Exit For
End If
Next
End Sub
Depending on how many UserForms you have, it may be better to use Select
Case:
Private Sub CommandButton3_Click()
Dim myOption As Control
Dim myTag As String
For Each myOption In grpInput.Controls
If myOption.Value = True Then
myTag = myOption.Tag
Exit For
End If
Next myOption
Me.Hide
Select Case myTag
Case "UserForm2"
UserForm2.Show
Case "UserForm3"
UserForm3.Show
End Select
Me.Show
End Sub
HTH
Quote:
> Hi,
> I use a number of userforms to control input into a worksheet. Userform1
> (called frmStart) needs to open a next form depending on the type of input
> chosen.
> The code I use from a textbook doesn't work:
> frmStart contains a frame with optionbuttons to determine what type of
input
> the users wants.
> Dim myOption As Control
> Dim myInput
> For Each myOption In grpInput.Controls
> If myOption.Value = True Then
> myInput = myOption.Caption
> End If
> Next myOption
> The problem with this piece of code is that I don't get Value in the 2nd
> line of the If-structure in the pop-up box. It only lists visible. It's
> listing the possibilities for the frame grpInput instead of the properties
> for the optionbuttons.
> I also need a way to run the chosen userform when the if-structure has
> determined which optionbutton is active.
> Any ideas???
> Thanks
> Jeroen Bouwman