PDA

View Full Version : Frame visible properties



av8tordude
04-17-2011, 08:42 PM
I have 4 frames on a userform. I have a button on sheet 1, 2, 3, 4. How can I call a userform and make visible only the frame that corresponds to the sheet the button was used.

example...

If I'm on sheet1 and I click the button to display the userform, only frame1 should be visible. All other frames (2,3,&4) should be invisible.

If I'm on sheet2 and I click the button to display the userform, only frame2 should be visible. All other frames (1,3,&4) should be invisible.

etc.

Thanks for you help

Jan Karel Pieterse
04-17-2011, 09:56 PM
You could add an argument to the sub that shows the userform:

In your form place this code:

Option Explicit
Public Frame2Show As Integer
Public Sub Initialize()
Dim iFrame As Integer
For iFrame = 1 To 4
With Me.Controls("Frame" & iFrame)
If iFrame = Frame2Show Then
.Visible = True
Else
.Visible = False
End If
End With
Next
End Sub

The sub to show the form:

Sub ShowForm(iFrame As Integer)
Dim ufForm As UserForm1
Set ufForm = New UserForm1
With ufForm
.Frame2Show = iFrame
.Initialize
.Show
End With
End Sub