Solved Password Protect TabCtl (1 Viewer)

Harry Taylor

Registered User.
Local time
Today, 12:06
Joined
Jul 10, 2012
Messages
73
Hi programmers,

More help if you can 😊

I have the following tab control on a form;
TabCtl429

1714735328503.png


Tab1 = Page430
Tab2 = Page431
Tab3 = Page444

I want to password protect Tab2 (Move Records) with password “1925”
Ideally so you cant even see the buttons.

If the password is incorrect etc go to field S_Contact

(Tab1 & 3 not password protected)

I've googled and got a code but doesn't work 100%

Any help would be appreciated
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:06
Joined
Sep 21, 2011
Messages
14,451
And you cannot show your code? :(
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:06
Joined
Oct 29, 2018
Messages
21,542
In the Change event of the tab control, maybe something like:

Code:
If Me.TabCtl=2 Then
    If Inputbox("Password")<>"1925" Then
        Me.TabCtl=1
    End If
End If
 

Harry Taylor

Registered User.
Local time
Today, 12:06
Joined
Jul 10, 2012
Messages
73
I think i'm there;

Private Sub TabCtl429_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 TabCtl429.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 Password Entered", , "Access Denied"
TabCtl429.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 ("Incorrect Password")
TabCtl429.Pages.Item(0).SetFocus

Exit Sub
End If
End If

End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:06
Joined
May 21, 2018
Messages
8,605
Code:
Private Sub TabCtl2_Change()

  Const TabName = "tabCtl2" ' name of your tab
  Const PageNumber = 1  'The index of page to hide. remember they are zero based
  Const Password = "ABC"  'your password

  Dim strInput As String
  Dim ctl As Control

' Hide controls on tab until correct password is entered
'Set focus on something that you are not going to hide.  If not you will through an error if something on the page has focus and you try to hide it
    Me.Combo0.SetFocus
    For Each ctl In Me.Controls  ' need me.controls
      If ctl.Tag = "*" Then ctl.Visible = False
    Next ctl

' If tab page with Tab Index of 1 is selected
' show InputBox asking for password
If Controls(TabName).Value = PageNumber 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 & "" = "" Then
      MsgBox "Must provide a Password", , "Access Denied"
      Me.Controls(TabName).Value = 0
    ElseIf strInput <> Password Then
      MsgBox "Wrong Password", , "Access Denied"
      Me.Controls(TabName).Value = 0
    Else
      For Each ctl In Me.Controls
      If ctl.Tag = "*" Then
        ctl.Visible = True
      End If
      Next ctl
    End If
End If
End Sub
 

Users who are viewing this thread

Top Bottom