Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Location
    Australia
    Posts
    23

    Question Unanswered: How can i hide tab items again after it loses focus?

    Hi all,

    I have created a form which contains a tabbed control with 3 tabs (Start, User 1 and User 2)

    I have added a password protect code to the tabs (User 1 and User 2) so that when clicked, the user is prompted for a password.

    I have created the user input as a string and have hidden the tab content by using a tag on each item and the visible command. If the wrong password is entered, the content remains hidden and returns to the start tab. If the correct password is entered, the items with the specified tag become visible.

    Its only a very basic password protection and isnt protecting vital content but i have a problem i would like to fix.

    This is the issue.
    If i select the user 1 tab and enter the password correctly, then i click the user 2 tab and enter the password correctly THEN click the User 1 tab again...I am prompted again for the password (which is fine), but all the items on the tab are still visible.

    I want to be able to re-hide the tab items when it loses focus so if i switch back to the tab, it is clear. I am unsure on how to do this.

    The code is entered on the OnChange Property of the tabset.

    Code:
    Private Sub TabCtl89_Change()
    'Define Variable Strings
    Dim strInputUser1 As String
    Dim strInputUser2 As String
    Dim ctl As Control
    
    'Hide specific tags. All combo boxes, labels etc are hidden if they have the tag in their property
    For Each ctl In Controls
        If ctl.Tag = "*user1" Then
        If ctl.Tag = "*user2" Then
            ctl.Visible = False
        End If
        End If
    
    'Make Password Protected Labels Visible on each tab (this is just a label that is visible before password entry and invisible when password is entered correctly)
        If ctl.Tag = "*pwuser1" Then
        If ctl.Tag = "*pwuser2" Then
            ctl.Visible = True
            End If
            End If
        Next ctl
        
    
    'USER 1 TAB
    
    'Overview: If the first tab of the tabset is clicked, show an Input Box for the password
    'Start = Index 0, User 1 = Index 1, User 2 = Index 2
    
    If TabCtl89.Value = 1 Then
        strInputUser1 = InputBox("Enter Tab Access Password", "Restricted Access")
        
    'If Password Box is empty return to Start Tab (Index 0)
        If strInputUser1 = " " Or strInputUser1 = Empty Then
            MsgBox "No Input Provided", , "Required Data"
            TabCtl89.Pages.Item(0).SetFocus
            Exit Sub
        End If
            
    'If the entered password = the specified password below (User1Password), make all tagged items visible or not visible.
    If strInputUser1 = "User1Password" Then
        For Each ctl In Controls
            If ctl.Tag = "*User1" Then
                ctl.Visible = True
            End If
             If ctl.Tag = "*pwUser1" Then
                ctl.Visible = False
            End If
        Next ctl
    
    
    'If the password is incorrect, show message and return to the start tab.
        Else
            MsgBox ("Access Denied - Check Password or Select Correct Tab")
            TabCtl89.Pages.Item(0).SetFocus
            Exit Sub
        End If
    End If
    
    
        
    
    'USER 2 TAB
    
    If TabCtl89.Value = 2 Then
        strInputUser2 = InputBox("Enter Tab Access Password", "Restricted Access")
        
        If strInputUser2 = " " Or strInputUser2 = Empty Then
            MsgBox "No Input Provided", , "Required Data"
            TabCtl89.Pages.Item(0).SetFocus
            Exit Sub
        End If
        
    If strInputUser2 = "User2Password" Then
        For Each ctl In Controls
            If ctl.Tag = "*User2" Then
                ctl.Visible = True
            End If
             If ctl.Tag = "*pwUser2" Then
                ctl.Visible = False
            End If
    
        Next ctl
    
    
        Else
            MsgBox ("Access Denied - Check Password or Select Correct Tab")
            TabCtl89.Pages.Item(0).SetFocus
            Exit Sub
        End If
    End If
               
    End Sub
    I am quite new to coding and am not sure how to solve this. Another option i was thinking of was to hide the other user tabs when the password is entered correctly on the selected tab. Not sure how to do that either.

    Any suggestions would be appreciated.

    Thankx

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    If I understand your explanation correctly, I think your problem is in this bit of code

    Code:
    For Each ctl In Controls
        If ctl.Tag = "*user1" Then
        If ctl.Tag = "*user2" Then
            ctl.Visible = False
        End If
        End If
    It should be

    Code:
    For Each ctl In Controls
        If ctl.Tag = "*user1" Or ctl.Tag = "*user2" Then
         ctl.Visible = False
        End If
    You need to make the same type of correction for your code to make the Password Labels Visible.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    May 2012
    Location
    Australia
    Posts
    23
    By combining the two tags i get an error because its trying to set visible to false on the tab in focus.

    I think i will just keep it how it is. Its not hiding private information and access is still denied to the tab without a password.

Posting Permissions

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