+ Reply to Thread
Results 1 to 4 of 4

Thread: Password Protected Tabs

  1. #1
    Lightning Master AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123's Avatar
    Join Date
    Mar 2008
    Location
    Fortress Of Solitude
    Posts
    394
    Rep Power
    7

    Password Protected Tabs

    Chances are,. if you've used tab controls you don't want all your users to gain access to everything.

    The following sample shows an easy way to password protect your tabs,

    The main tabcontrol is called tabctl.

    You will notice in the command button event,. we are referencing this,.. in order to set focus based on the strInput of the password.

    If a correct password is entered tabs tagged with a "*" will be opened and become visible.

    Code:
    Private Sub Command_Click()
       Dim strInput As String
        Dim ctl As Control
        
            strInput = InputBox("Please enter a password to access this tab" & vbNewLine & vbNewLine & "PASSWORD = password", _
                                "Restricted Access")
    
            If strInput = "" Or strInput = Empty Then
                MsgBox "No Input Provided", , "Required Data"
                TabCtl.Pages.Item(0).SetFocus
                Exit Sub
            End If
    
            If strInput = "password" Then
    
                For Each ctl In Controls
                    If ctl.Tag = "*" Then
                        ctl.Visible = True
                    End If
                Next ctl
                ' If incorrect password supplied return to tab (index 0)
            Else
                MsgBox ("Sorry, you do not have access to this information")
                TabCtl.Pages.Item(0).SetFocus
    
                Exit Sub
            End If
     
    End Sub
    
    Code:
    Private Sub Form_Current()
            'Hide controls tagged with "*" until password entered.
        Dim ctl As Control
        For Each ctl In Controls
            If ctl.Tag = "*" Then
                ctl.Visible = False
            End If
        Next ctl
        
    End Sub
    
    See attached example
    Attached Files
    Last edited by AOG123; June 13th, 2008 at 03:20 PM. Reason: Edit: Attachment adjustment made,. Simplified code provided by Rural Guy
    If i helped you, make me famous by clicking the

  2. #2
    Barn Newbie RuralGuy will become famous soon enough RuralGuy's Avatar
    Join Date
    Mar 2008
    Posts
    44
    Rep Power
    4

    I would think you could simplify the code to:
    Code:
    Private Sub Command_Click()
       Dim ctl As Control
    
       If InputBox("Please enter a password to access this tab" & _
                   vbNewLine & vbNewLine & "PASSWORD = password", _
                   "Restricted Access") = "password" Then
    
          For Each ctl In Me.Controls
             If ctl.Tag = "*" Then
                ctl.Visible = True
             End If
          Next ctl
       Else
          ' If incorrect password supplied return to tab (index 0)
          MsgBox ("Sorry, you do not have access to this information")
          Me.TabCtl.Pages.Item(0).SetFocus
       End If
    
    End Sub
    
    Sorry but I couldn't resist.

  3. #3
    Lightning Master AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123's Avatar
    Join Date
    Mar 2008
    Location
    Fortress Of Solitude
    Posts
    394
    Rep Power
    7

    Rural Guy,

    Thanks for the simplified code,.. i have been known on occasions to go the long way around things.

    I have updated the sample

    AOG
    If i helped you, make me famous by clicking the

  4. #4
    Barn Newbie RuralGuy will become famous soon enough RuralGuy's Avatar
    Join Date
    Mar 2008
    Posts
    44
    Rep Power
    4

    AOG,
    Glad I can help out once in a while.

+ Reply to Thread

Similar Threads

  1. Hashing (Encryption) Password & Other Sensitive Information
    By BLaaaaaaaaaarche in forum ASP Code Samples
    Replies: 5
    Last Post: February 23rd, 2009, 10:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO