Hi there,
Hope someone can assist me regarding password on a tab in a form
I wish to hide content of tab until password is entered.
Below see me code which I got from access site the code works perfectly in the example but not when I use it on my form
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please read this for further information:-
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Please feel free to Remove this Comment
I am using Access 2007 and the code was written for 2002
Thanx in advance
Hope someone can assist me regarding password on a tab in a form
I wish to hide content of tab until password is entered.
Below see me code which I got from access site the code works perfectly in the example but not when I use it on my form
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please read this for further information:-
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Please feel free to Remove this Comment
Code:
Option Compare Database
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
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" & vbNewLine & vbNewLine & "PASSWORD = password", _
"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
I am using Access 2007 and the code was written for 2002
Thanx in advance
Last edited by a moderator: