issue with multipage userform

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello all,
Is there a way I may restrict access to a page on a multi page userform?

Thanks
Kelly
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Thats hard to do. Selecting just the Multipage and not just a page is hard to do I tried it. That's why I suggeted the script

Not really - just click on the control, then click on its border. :)
 
Upvote 0
Yes, many times. First click selects the current page and highlights the control with a border. Second click on the border selects the actual multipage control. You can also just Ctrl+Click the control initially to select the multipage rather than the page - I tend to forget to press Ctrl initially, which is why I use the border click.
 
Last edited:
Upvote 0
.
Paste this into the UserForm level module :

Code:
Option Explicit


Private Sub CommandButton1_Click()


Dim x As String
Dim i As Integer
Me.MultiPage1.Pages(1).Visible = False
101:
     x = InputBox("Enter your Password.", "Password Required")
If x = "123" Then
    'Success!
    'Continue with your macro because the user typed the correct macro
    MsgBox "Welcome!"
    Me.MultiPage1.Pages(1).Visible = True
    Me.MultiPage1.Value = 1
Else
    If i <= 1 Then
        MsgBox "Invalid Password. Try again. You have " & (2 - i) & " tries left."
        i = i + 1
        GoTo 101:
    Else
        MsgBox "Incorrect password entered too many times. Try again later."
        Application.Visible = False
        Application.Quit
        
        Exit Sub
    End If
End If
End Sub


Private Sub UserForm_Initialize()
    Me.MultiPage1.Pages(1).Visible = False
End Sub

So how will I use just one button so that multiple users can access their assigned page?

Thanks
 
Upvote 0
.
:eek:
Code:
MsgBox "Incorrect password entered too many times. Try again later."
Application.Visible = False
Application.Quit

Very harsh, don't you think? :ROFLMAO:



Much kinder approach than :

Code:
MsgBox "Incorrect password entered too many times. Try again later."
        Dim i as Integer
    For i = 1 to 5
        If i = 5 then
            MsgBox "Bye Bye !"
            Environ("username").SelfDestruct = True
        End If
    Next i



(y)
 
Last edited:
Upvote 0
.
Code:
Option Explicit


Private Sub CommandButton1_Click()


Dim x As String
Dim i As Integer
Me.MultiPage1.Pages(1).Visible = False
Me.MultiPage1.Pages(2).Visible = False
101:
     x = InputBox("Enter your Password.", "Password Required")
If x = "123" Then
    'Success!
    'Continue with your macro because the user typed the correct macro
    MsgBox "Welcome!"
    Me.MultiPage1.Pages(1).Visible = True
    Me.MultiPage1.Value = 1
ElseIf x = "456" Then
    'Continue with your macro because the user typed the correct macro
    MsgBox "Welcome!"
    Me.MultiPage1.Pages(2).Visible = True
    Me.MultiPage1.Value = 2
Else
    If i <= 1 Then
        MsgBox "Invalid Password. Try again. You have " & (2 - i) & " tries left."
        i = i + 1
        GoTo 101:
    Else
        MsgBox "Incorrect password entered too many times. Try again later."
        Application.Visible = False
        Application.Quit
        
        Exit Sub
    End If
End If
End Sub


Private Sub UserForm_Initialize()
    Me.MultiPage1.Pages(1).Visible = False
End Sub
 
Upvote 0
.
Code:
Option Explicit


Private Sub CommandButton1_Click()


Dim x As String
Dim i As Integer
Me.MultiPage1.Pages(1).Visible = False
Me.MultiPage1.Pages(2).Visible = False
101:
     x = InputBox("Enter your Password.", "Password Required")
If x = "123" Then
    'Success!
    'Continue with your macro because the user typed the correct macro
    MsgBox "Welcome!"
    Me.MultiPage1.Pages(1).Visible = True
    Me.MultiPage1.Value = 1
ElseIf x = "456" Then
    'Continue with your macro because the user typed the correct macro
    MsgBox "Welcome!"
    Me.MultiPage1.Pages(2).Visible = True
    Me.MultiPage1.Value = 2
Else
    If i <= 1 Then
        MsgBox "Invalid Password. Try again. You have " & (2 - i) & " tries left."
        i = i + 1
        GoTo 101:
    Else
        MsgBox "Incorrect password entered too many times. Try again later."
        Application.Visible = False
        Application.Quit
        
        Exit Sub
    End If
End If
End Sub


Private Sub UserForm_Initialize()
    Me.MultiPage1.Pages(1).Visible = False
End Sub

Okay thanks.

How many times can I use the ElseIf?

Can I do that up to say 10 times?

Regards
Kelly
 
Upvote 0
.
Give it a try and see.

If it begins to show issues, you may have to try a SELECT CASE statement in place of the IF / ELSEIF
 
Upvote 0
.
Give it a try and see.

If it begins to show issues, you may have to try a SELECT CASE statement in place of the IF / ELSEIF

Wow. I will use the case statement since I am cool with that than the if things.

I will come back here when I get stucked
Thanks again
Kelly
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,488
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top