Share via

VBA userform multipage

Anonymous
2013-10-25T13:13:26+00:00

My UserForm has two Pages. Depending on the Page selected, how do I show a Calendar in the Frame?

My failed attempt is ........

Private Sub MultiPage1_Change()

With Me.MultiPage1

    Select Case .Name

        Case "Page1"

                Me.Calendar1.Visible = False

        Case "Page2"

                Me.Calendar1.Visible = True

    End Select

End With

End Sub

How can I code this correctly?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2013-10-25T13:50:39+00:00

In theory at least

Private Sub MultiPage1_Change()

    With Me.MultiPage1

        Select Case .Value

            Case 0: Me.Calendar1.Visible = False

            Case 1: Me.Calendar1.Visible = True

        End Select

    End With

End Sub

should work, but I know from previous experience that calendar controls do not always behave as expected when you attempt to hide them, so an alternative approach is to move them off the userform's visible area e.g. assuming the userform width is (say) 240, put the left property of the control beyond this e.g. 250, then when you want it visible, change its left property back to its original position - here 60. This invariably works where the visibility option doesn't.

It helps to set the userform width in the vba editor wide enough to display the moved control, and set the width to its normal state in the userform initialization.

Private Sub MultiPage1_Change()

    With Me.MultiPage1

        Select Case .Value

            Case 0: Me.Calendar1.Left = 250

            Case 1: Me.Calendar1.Left = 60

        End Select

    End With

End Sub

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-10-28T08:30:59+00:00

    Thanks, code works perfectly!

    No need to move them 'off-screen'.

    Was this answer helpful?

    0 comments No comments