Want to hide the 2nd tab on the form: (1 Viewer)

chohan78

Registered User.
Local time
Today, 05:19
Joined
Sep 19, 2013
Messages
67
Hello !

Need help again from the group please :mad:

I want to password protect the second tab control page, so I'm using this 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 IfEnd 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:
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. so basically it is not hiding the tab.. :confused:
How do I fix this, please ?
Thanks
 

chohan78

Registered User.
Local time
Today, 05:19
Joined
Sep 19, 2013
Messages
67
Hello !

Need help again from the group please :mad:

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



Code:
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] TabCtl0_Change()

  [COLOR=blue]Dim[/COLOR] strInput [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR]
  [COLOR=blue]Dim[/COLOR] ctl [COLOR=blue]As[/COLOR] Control

  [COLOR=green]' Hide controls on tab until correct password is entered[/COLOR]
  [COLOR=blue]For[/COLOR] [COLOR=blue]Each[/COLOR] ctl [COLOR=blue]In[/COLOR] Controls
    [COLOR=blue]If[/COLOR] ctl.Tag = [COLOR=#A31515]"*"[/COLOR] [COLOR=blue]Then[/COLOR]
      ctl.Visible = [COLOR=blue]False[/COLOR]
    [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
  [COLOR=blue]Next[/COLOR] ctl

  [COLOR=green]' If tab page with Tab Index of 1 is selected[/COLOR]
  [COLOR=green]' show InputBox asking for password[/COLOR]
  [COLOR=blue]If[/COLOR] TabCtl0.Value = 1 [COLOR=blue]Then[/COLOR]
    strInput = InputBox([COLOR=#A31515]"Please enter a password to access this tab"[/COLOR], _
              [COLOR=#A31515]"Restricted Access"[/COLOR])

    [COLOR=green]' Check if value is entered into InputBox[/COLOR]
    [COLOR=green]' If no value entered display MsgBox[/COLOR]
    [COLOR=blue]If[/COLOR] strInput = [COLOR=#A31515]""[/COLOR] [COLOR=blue]Or[/COLOR] strInput = Empty [COLOR=blue]Then[/COLOR]
      MsgBox [COLOR=#A31515]"No Input Provided"[/COLOR], , [COLOR=#A31515]"Required Data"[/COLOR]
      TabCtl0.Pages.Item(0).SetFocus
      [COLOR=blue]Exit[/COLOR] [COLOR=blue]Sub[/COLOR]
    [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]

    [COLOR=green]' Check InputBox value and if value is a match[/COLOR]
    [COLOR=green]' display tab and unhide hidden fields[/COLOR]
    [COLOR=blue]If[/COLOR] strInput = [COLOR=#A31515]"password"[/COLOR] [COLOR=blue]Then[/COLOR]

      [COLOR=blue]For[/COLOR] [COLOR=blue]Each[/COLOR] ctl [COLOR=blue]In[/COLOR] Controls
        [COLOR=blue]If[/COLOR] ctl.Tag = [COLOR=#A31515]"*"[/COLOR] [COLOR=blue]Then[/COLOR]
          ctl.Visible = [COLOR=blue]True[/COLOR]
        [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
      [COLOR=blue]Next[/COLOR] ctl
      [COLOR=green]' If incorrect password supplied return to tab (index 0)[/COLOR]
    [COLOR=blue]Else[/COLOR]
      MsgBox ([COLOR=#A31515]"Sorry, you do not have access to this information"[/COLOR])
      TabCtl0.Pages.Item(0).SetFocus

      [COLOR=blue]Exit[/COLOR] [COLOR=blue]Sub[/COLOR]
    [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
  [COLOR=blue]End[/COLOR] [COLOR=blue]If

End[/COLOR] [COLOR=blue]Sub[/COLOR]

then to hide the controls in the first place, we do this using the Tag Property, and in the OnCurrent event of the form:
[COLOR=black][COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Form_Current()    [COLOR=green]'Hide controls tagged with "*" until password entered.[/COLOR]  [COLOR=blue]Dim[/COLOR] ctl [COLOR=blue]As[/COLOR] Control  [COLOR=blue]For[/COLOR] [COLOR=blue]Each[/COLOR] ctl [COLOR=blue]In[/COLOR] Controls    [COLOR=blue]If[/COLOR] ctl.Tag = [COLOR=#A31515]"*"[/COLOR] [COLOR=blue]Then[/COLOR]      ctl.Visible = [COLOR=blue]False[/COLOR]    [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]  [COLOR=blue]Next[/COLOR] ctl  [COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR][/COLOR]
[COLOR=black][FONT=Verdana]The password request and events works fine but when prompting for the password it still shows the second page items and info. so basically it is not hiding the tab..
How do I fix this, please ?
Thanks [/FONT][/COLOR]

UG EDIT - 2020/07/06
Because this code is an unreadable mess, and I happened upon what I think is the original code, can't be absolutely certain, but I thought I would post a link to the original code, what I think is the original code to be more exact:-

 
Last edited by a moderator:

pr2-eugin

Super Moderator
Local time
Today, 05:19
Joined
Nov 30, 2011
Messages
8,494
You need to debug. I use the same code in my applications, it works just fine. Are you sure you have set the tags property for all the controls you want to hide with a * in design view?
 

chohan78

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

how to set the tag property ??

I added the code in the on Current event of the form as well?
 

chohan78

Registered User.
Local time
Today, 05:19
Joined
Sep 19, 2013
Messages
67
is there any effect by using the Switchboard ? I am opeining the forms via switchboard.
 

pr2-eugin

Super Moderator
Local time
Today, 05:19
Joined
Nov 30, 2011
Messages
8,494
Open the form in Design view. Go to the tab control and select the controls you wish to hide, then go to the properties window, under the "Other" tab you will have the property "Tag", where you can enter the *.
 

Users who are viewing this thread

Top Bottom