Results 1 to 4 of 4

Thread: [Acces 2003 + VBA] Password Protecting A Microsoft Access Tab Control

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    NB, Canada
    Posts
    52

    [Acces 2003 + VBA] Password Protecting A Microsoft Access Tab Control

    Hi guys,

    I want to password protect the second tab control page, so I'm using this code :

    Code:
    Private Sub TabCtl0_Change()
    
      Dim strInput As String
      Dim ctl As Control
    
      ' Hide controls on tab until correct password is entered
      For Each ctl In Controls
        If ctl.Tag = "*" Then
          ctl.Visible = False
        End If
      Next ctl
    
      ' If tab page with Tab Index of 1 is selected
      ' show InputBox asking for password
      If TabCtl0.Value = 1 Then
        strInput = InputBox("Please enter a password to access this tab", _
                  "Restricted Access")
    
        ' Check if value is entered into InputBox
        ' If no value entered display MsgBox
        If strInput = "" Or strInput = Empty Then
          MsgBox "No Input Provided", , "Required Data"
          TabCtl0.Pages.Item(0).SetFocus
          Exit Sub
        End If
    
        ' Check InputBox value and if value is a match
        ' display tab and unhide hidden fields
        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")
          TabCtl0.Pages.Item(0).SetFocus
    
          Exit Sub
        End If
      End If
    
    End Sub
    then to hide the controls in the first place, we do this using the Tag Property, and in the OnCurrent event of the form:

    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
    The password request and events works fine but when prompting for the password it still shows the second page items and info...

    How do I fix this, please ?

    Thanks

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [Acces 2003 + VBA] Password Protecting A Microsoft Access Tab Control

    Place a breakpoint on "If strInput = "password" Then" and press F8 to step line by line through your code to see if it behaves the way you expect.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [Acces 2003 + VBA] Password Protecting A Microsoft Access Tab Control

    Where do you set the Tag properties to "*" ?

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    NB, Canada
    Posts
    52

    Re: [Acces 2003 + VBA] Password Protecting A Microsoft Access Tab Control

    I'm sorry I didn't understand your question?!

Posting Permissions

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



Click Here to Expand Forum to Full Width