?
Solved

Password protecting part of tabstrip

Posted on 2010-01-07
5
Medium Priority
?
469 Views
Last Modified: 2013-12-26
I have a userform using a tabstrip control.  On of the tabs is a management tab and should only be accessed by certain people...preferrably password protected.  Users do not have to login to the sheet otherwise and that's not an option.  What I'd like to do is when a user attempts to access that tab, a prompt pops up asking for a password.  If correct, the tab is show but if not, the user gets an error.

Any help is appreciated,
Chris
0
Comment
Question by:chris_thorn
  • 2
4 Comments
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 26200187
Chris,
You can use something like this, but again this will ask for the password when user selects that tab and its shown, however if the password dont match it selects sheet2 and this code goes in the sheet module of that sheet for which you want to ask for password, The password i saved in this case was abc.
Saurabh...

Private Sub Worksheet_Activate()
    Application.ScreenUpdating = False

    Dim pswrd As String

    pswrd = Application.InputBox("Please enter password to view the sheet", "Enter Password", Type:=2)

    If pswrd <> "abc" Then

        MsgBox "Incorrect Password Entered"
        Sheets("sheet2").Select
    End If

    Application.ScreenUpdating = True
End Sub

Open in new window

0
 

Author Comment

by:chris_thorn
ID: 26200445
Thanks for the feedback...the answer you posted seems like you are attempting to protect an individual sheet.  I'm trying to protect a tab on a tabstrip placed on a user form.

Any thoughts?

Chris
0
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 26200568
Ahh i see what you mean, Can you post your sample workbook so that i can have a look.
0
 
LVL 22

Accepted Solution

by:
danaseaman earned 2000 total points
ID: 26276047
This snippet is for Vb6 but should be similar to VBA.
Controls for each Tab are placed in a Frame.
For Password protected Tab, user must input corrrect Password for Frame to become visible.

Option Explicit

Private SelectedTab As Integer

Private Sub Form_Load()
Dim i As Integer

    ' Move all the frames to the same position
    ' and make them all invisible.
    For i = 1 To ChoiceFrame.UBound
        ChoiceFrame(i).Move _
            ChoiceFrame(0).Left, _
            ChoiceFrame(0).Top, _
            ChoiceFrame(0).Width, _
            ChoiceFrame(0).Height
        ChoiceFrame(i).Visible = False
    Next i
    
    ' Select the first tab.
    SelectedTab = 1
    TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
    ChoiceFrame(SelectedTab - 1).Visible = True
End Sub

Private Sub TabStrip1_Click()
    Dim sPass  As String
    Dim bAllow As Boolean
    
    ChoiceFrame(SelectedTab - 1).Visible = False
    SelectedTab = TabStrip1.SelectedItem.Index
    If SelectedTab = 3 Then
       sPass = InputBox("Input Passwqord", "Password Required")
       If sPass = "MyPassword" Then
          ChoiceFrame(SelectedTab - 1).Visible = True
       Else
          MsgBox "Incorrect password"
       End If
    Else
       ChoiceFrame(SelectedTab - 1).Visible = True
    End If
    
End Sub

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question