Hiding some pages on multi page form

G

Guest

I have a multipage form used to colloect user data. I would like to hide some
of the pages and show them only if a valid password has been entered. Can
anyone help?
 
D

Dave Peterson

I created a small userform with 3 commandbuttons, a multipage with 5 pages, and
a textbox.

commandbutton1 and textbox1 were used to get the password.
commandbutton2 was used to cancel (and unload the form)
commandbutton3 was used as the "real" ok button

This is the code I had under the userform:

Option Explicit
Private Sub CommandButton1_Click()

Const CorrectPWD As String = "hi"

Dim iCtr As Long
Dim myPagesToSee() As Boolean
ReDim myPagesToSee(0 To Me.MultiPage1.Pages.Count - 1)

'hide the password box and its button
Me.TextBox1.Visible = False
Me.CommandButton1.Visible = False

For iCtr = 0 To Me.MultiPage1.Pages.Count - 1
'default to show the page
myPagesToSee(iCtr) = True
Next iCtr

If Me.TextBox1.Value = CorrectPWD Then
'ok to see everything, don't change anything
Else
'my test choices to hide (showing 1 & 2)
myPagesToSee(0) = False
myPagesToSee(3) = False
myPagesToSee(4) = False
End If

For iCtr = 0 To Me.MultiPage1.Pages.Count - 1
Me.MultiPage1.Pages(iCtr).Visible = myPagesToSee(iCtr)
Next iCtr

Me.CommandButton2.Visible = True
Me.MultiPage1.Visible = True
End Sub
Private Sub CommandButton3_Click()
'always cancel
Unload Me
End Sub
Private Sub UserForm_Initialize()

'hide all the multipage
MultiPage1.Visible = False

Me.TextBox1.Visible = True
With Me.CommandButton1
.Visible = True
.Caption = "Ok"
End With

With Me.CommandButton2
.Visible = False
.Caption = "Ok"
End With

With Me.CommandButton3
.Visible = True
.Caption = "Cancel"
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top