Go Back   DeveloperBarn Forums > Databases > Microsoft Access

Sponsored Links

Discuss "Password Protected Tabs" in the Microsoft Access forum.

Microsoft Access - Microsoft Access is a database for small to medium applications. Learn tips and tricks and best database practices here.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old June 10th, 2008, 10:12 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default 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
File Type: zip TabPassword2.zip (14.5 KB, 10 views)
__________________
If i helped you, make me famous by clicking the

Last edited by AOG123; June 13th, 2008 at 02:20 PM. Reason: Edit: Attachment adjustment made,. Simplified code provided by Rural Guy
Reply With Quote
The Following User Says Thank You to AOG123 For This Useful Post:
jchrisf (June 20th, 2008)
Sponsored Links
  #2  
Old June 13th, 2008, 01:07 PM
Barn Newbie

 
Join Date: Mar 2008
Posts: 15
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Power: 1
RuralGuy is on a distinguished road
Default

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.

Comments on this post
AOG123 agrees:
jmurrayhead agrees: Nice
BLaaaaaaaaaarche agrees:
lewy agrees:
jchrisf agrees:
Reply With Quote
The Following 2 Users Say Thank You to RuralGuy For This Useful Post:
AOG123 (June 13th, 2008), BLaaaaaaaaaarche (June 13th, 2008)
  #3  
Old June 13th, 2008, 02:22 PM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

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
Reply With Quote
  #4  
Old June 13th, 2008, 03:20 PM
Barn Newbie

 
Join Date: Mar 2008
Posts: 15
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Power: 1
RuralGuy is on a distinguished road
Default

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

  DeveloperBarn Forums > Databases > Microsoft Access

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[ASP/VBScript] Hashing (Encryption) Password & Other Sensitive Information BLaaaaaaaaaarche Code Samples 1 November 3rd, 2008 11:44 PM


All times are GMT -4. The time now is 06:25 PM.



Content Relevant URLs by vBSEO 3.2.0