Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password protected tab-control (through a form not inputbox)

Status
Not open for further replies.

Heejoe

Technical User
Jun 12, 2009
13
GB
Dear users,

I am now trying to secure certain "pages" of my main form. About three sections of my tabcontrol must be password protected.

I had it working through a control button with pw protection but my users needed more features:
(below I have posted my code)
- I want the users to enter the password in another form "dialox box pw" with an password inputmask (goal is to not show the input)
- Once entered the users is free to go. Now they have to enter the pw for every record they select (since it is a private sub I guess)

Hope you can help me. A 4 hour browse on this great forum and others has helped but I am stuck now...

Thanks a lot in advance

Haio

Code:
 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 Toggle159.Value = True Then
        strInput = InputBox("Please enter a password to access FAR data","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"
            TabCtl49.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 = "MYPASSWORD" 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")
            TabCtl49.Pages.Item(0).SetFocus
 
create your form with the textbox that has the password input mask and an OK button. Give the form and textbox names, for example frmPass and txtPass.

Instead of

Code:
strInput = InputBox("Please enter a password to access FAR data","Restricted Access")

use

Code:
DoCmd.OpenForm("frmPass")

to open the password form and move the code you use for password validation to the on_click event of the OK button on frmPass. You'll need to reference your main form when you make controls visible. For example, if you main form name is frmMain, then I think you can use:

Code:
For each ctl In form_frmMain.Controls
...
Next
 
Thanks Joelflorendo,

I am so close after your input. The only thing missing now is that the object
Code:
form_frmMain.Controls
is not recognized (of course I have selected the name of my own form....:)).

Any idea how to resolve this?

Will this also solve the part where it "resets" the security for every record?

Thanks a lot for your help.

Haio
 
try
Code:
Forms!frmMain.Controls

I'm not sure why it's resetting the security for every record. It depends on when you're firing the "hide controls" code. You might want to only run that when the form is open perhaps(?)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top