Hiding fields in tab controlled form (1 Viewer)

chohan78

Registered User.
Local time
Today, 05:20
Joined
Sep 19, 2013
Messages
67
:confused:
hi,
I am using a tab controlled form of 5-6 tabs and want to protect 3-4 tabs with a password. Password code is working but not able to hide the data on the forms during the time when I entered the password. Not sure how to use the tag property? ""HELP PLEASE""


Private Sub TabCtl0_Change()

Dim strInput As String
Dim ctl As Control

If ctl.Tag = "*" Then
ctl.Visible = False
End If
Next ctl


If TabCtl0.Value = 1 Then
strInput = InputBox("Please enter a password to access this tab", _
"Restricted Access")

If strInput = "" Or strInput = Empty Then
MsgBox "No Input Provided", , "Required Data"
TabCtl0.Pages.Item(0).SetFocus
Exit Sub
End If


If strInput = "***" Then

For Each ctl In Controls
If ctl.Tag = "*" Then
ctl.Visible = True
End If
Next ctl

Else
MsgBox ("Sorry, you do not have access to this information")
TabCtl0.Pages.Item(0).SetFocus

Exit Sub
End If
End If

End Sub

also

Private Sub Form_Current()


Dim ctl As Control
For Each ctl In Controls
If ctl.Tag = "*" Then
ctl.Visible = False
End If
Next ctl

End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:20
Joined
Aug 30, 2003
Messages
36,133
What exactly is the problem? Error, or? Did you put * in the Tag property of the desired controls?
 

Minty

AWF VIP
Local time
Today, 05:20
Joined
Jul 26, 2013
Messages
10,374
Try using something other than * for the tag - it's the Access wildcard symbol and I suspect is confusing the hell out of your code.

If "*" means if it's anything....
 

chohan78

Registered User.
Local time
Today, 05:20
Joined
Sep 19, 2013
Messages
67
hi,

only issue is that I want to hide the tab where I am entering the password. once password matches it should show the contents of the tab but currently it opens the form by showing the contents and password window appears as well.

I have also tried to add * in the tags property but when I open the form it hides the tabs where * added in the tag property due to the following code I think?

Dim strInput As String
Dim ctl As Control

If ctl.Tag = "*" Then
ctl.Visible = False
End If
Next ctl
 

Minty

AWF VIP
Local time
Today, 05:20
Joined
Jul 26, 2013
Messages
10,374
Yes you are telling it to hide the tab with that code. I don't think you can hide it and be on it at the same time.

Put a big blank box in front of all the controls on each tab. Hide it when the correct password is entered.

And like I said earlier - don't use * as a tag...
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:20
Joined
Aug 30, 2003
Messages
36,133
I personally would probably hide the tabs themselves rather than the contents, but that's up to you. If you're saying it's hiding the tab where you want them to enter a password, don't put * in the Tag property of that tab.

To Minty's point, it's certainly worth trying. I don't think it's the problem here, but could be in other situations so good to get in the habit of avoiding.
 

Minty

AWF VIP
Local time
Today, 05:20
Joined
Jul 26, 2013
Messages
10,374
Can you re-post up the actual code you are currently trying to use - and screen shot the tag property of the one of the controls that you want to hide.
Please use the code tags. (See the advanced editor and the # symbol)
 

chohan78

Registered User.
Local time
Today, 05:20
Joined
Sep 19, 2013
Messages
67
hi, I am struggling to attach the screen shot as there is no option in this screen. Tried to insert an image but it is asking the URL.

code is below: the tag option for all the forms is blank.


Private Sub TabCtl0_Change()

Dim strInput As String
Dim ctl As Control

If ctl.Tag = "*" Then
ctl.Visible = False
End If
Next ctl


If TabCtl0.Value = 1 Then
strInput = InputBox("Please enter a password to access this tab", _
"Restricted Access")

If strInput = "" Or strInput = Empty Then
MsgBox "No Input Provided", , "Required Data"
TabCtl0.Pages.Item(0).SetFocus
Exit Sub
End If


If strInput = "***" Then

For Each ctl In Controls
If ctl.Tag = "*" Then
ctl.Visible = True
End If
Next ctl

Else
MsgBox ("Sorry, you do not have access to this information")
TabCtl0.Pages.Item(0).SetFocus

Exit Sub
End If
End If

End Sub

also

Private Sub Form_Current()


Dim ctl As Control
For Each ctl In Controls
If ctl.Tag = "*" Then
ctl.Visible = False
End If
Next ctl

End Sub
 

Minty

AWF VIP
Local time
Today, 05:20
Joined
Jul 26, 2013
Messages
10,374
Okay - that code won't compile so can't work. The Next Ctl (blue) doesn't have the code in Red (added) so no loop to set the controls.

Code:
Private Sub TabCtl0_Change()

    Dim strInput         As String
    Dim ctl              As Control

  [COLOR="Red"]  For Each ctl In Controls[/COLOR]
        If ctl.Tag = "*" Then
            ctl.Visible = False
        End If
   [COLOR="Blue"] Next ctl[/COLOR]


    If TabCtl0.Value = 1 Then
        strInput = InputBox("Please enter a password to access this tab", _
                            "Restricted Access")

        If strInput = "" Or strInput = Empty Then
            MsgBox "No Input Provided", , "Required Data"
            TabCtl0.Pages.Item(0).SetFocus
            Exit Sub
        End If


        If strInput = "[COLOR="red"]PasswordString[/COLOR]" Then

            For Each ctl In Controls
                If ctl.Tag = "*" Then
                    ctl.Visible = True
                End If
            Next ctl

        Else
            MsgBox ("Sorry, you do not have access to this information")
            TabCtl0.Pages.Item(0).SetFocus

            Exit Sub
        End If
    End If

End Sub
[COLOR="Green"]'---------------------------------------------------------------------------------------[/COLOR]

Private Sub Form_Current()

    Dim ctl              As Control

    For Each ctl In Controls
        If ctl.Tag = "*" Then
            ctl.Visible = False
        End If
    Next ctl

End Sub

PasswordString will need replacing with the password you want to use.

You need to set the tag property for each control on the form NOT form itself.
the tag option for all the forms is blank.

You need to set the tag value to the value you are checking for, in your case * in the tag property highlighted below;


I still think I wouldn't use the * symbol personally but that's your choice.

When you post - underneath the quick reply box there is a button for advanced editor (Go Advanced). That will get you to the file attachment, code tags and other more advanced posting options.
 

Attachments

  • tag_Property.PNG
    tag_Property.PNG
    6.7 KB · Views: 195

chohan78

Registered User.
Local time
Today, 05:20
Joined
Sep 19, 2013
Messages
67
Hi,
thanks for your reply. As I explained previously that when I put the * in the tag property it hides the tab because of the code which we added at the start. According to this code all the controls which have a * in the tag hide them.

For Each ctl In Controls
If ctl.Tag = "*" Then
ctl.Visible = False
End If
Next ctl
 

Minty

AWF VIP
Local time
Today, 05:20
Joined
Jul 26, 2013
Messages
10,374
Don't hide the Tab - Hide the controls ON the tab.
 

Users who are viewing this thread

Top Bottom