Tab control password (1 Viewer)

PARSO

Registered User.
Local time
Today, 09:09
Joined
Dec 13, 2004
Messages
66
search and couldnt find anything to tell me how to do this.

i have a tab control with contains 8 tabs. but i only want 1 to be password protected.
i only need a password entry not a username+ password.

so in other words when the "audit" tab is clicked i want a password popup, user enters password and tab contents is shown. (i dont want it to open the audit form on its own i want it opened as the sub-form in the tab control.

Thanks in advance
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:09
Joined
Jul 9, 2003
Messages
16,268
The download available from the link below does basically what you want, however the user will be able to see the controls on the tab in this example. If you do not want the user to see the controls on the tap make them invisible by default and then you will have to modify the code so that when the correct password is entered the controls then become visible.

 
Last edited:

PARSO

Registered User.
Local time
Today, 09:09
Joined
Dec 13, 2004
Messages
66
update:

ok i have it hiding the labels, but when i move off the tab and then back again the labels are still showing, i need it to ask for the password each time the tab is selected

----

Thanks Uncle Gizmo!!

can anybody help me make the contents of the tab visable only when correct password is entered.

ive tryed using - Label6.Visible = True but im not sure if im using it in right place or if its correct anyway, can anybody help me on where and what to put the code??

thanxs in advance
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:09
Joined
Jul 9, 2003
Messages
16,268
Change "Private Sub TabCtl0_Change()" to this:

Code:
Private Sub TabCtl0_Change()
Dim strInput As String

If TabCtl0.Value = 2 Then
    Label6.Visible = False ' Add all your controls here to make them invisible again
    strInput = InputBox("Please Enter Password (Password is 1)  ", "PASSWORD REQUIRED")
        
        If strInput <> "1" Then
            TabCtl0.Pages.Item(0).SetFocus
            Exit Sub

            Else
            Label6.Visible = True
        End If
End If
End Sub
 

PARSO

Registered User.
Local time
Today, 09:09
Joined
Dec 13, 2004
Messages
66
how do i change the code to make it so a whole subform is hidden, rather than just a label? the subform is called "Audit".
when i change the component name to "audit" i get an error saying you cannot hide a control that has the focus"....how do i get around this?
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:09
Joined
Jul 9, 2003
Messages
16,268
Is the subform on the tab you are password protecting?
 

PARSO

Registered User.
Local time
Today, 09:09
Joined
Dec 13, 2004
Messages
66
yes, kinda like the attached
 

Attachments

  • TabPas.zip
    39 KB · Views: 370

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:09
Joined
Jul 9, 2003
Messages
16,268
Cannot hide a control that has the focus

This is quite a common problem, especially when you try to hide controls with the visible property. As you can see MS Access won't let you hide something that has the focus, so what you have to do is move the focus to another control. If you have one handy use that, but in your case you do not have another suitable control. What you have to do is create one! Now obviously you don't want anyone to see this new control either. However you cannot make this control invisible, because the same thing would happen, MS Access would not let you set focus to it. What you do is you make it invisible by changing its actual color. The control is present on the form and visible, but because it's the same color as the background you can't see it, if that makes any sense at all!

Once you have created your new control, in your code you divert focus with the set focus property to this new control this then allows you to make the other control invisible with the visible property.
 

PARSO

Registered User.
Local time
Today, 09:09
Joined
Dec 13, 2004
Messages
66
ok i htink i kinda understand, could you demo it on the above example pls?
use Label6 as the invisable control..
Thanks
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:09
Joined
Jul 9, 2003
Messages
16,268
Sorry, I should have added that you cannot set focus to a label control, that is why I said you will need to add another control, the best sort of control to add would be a text Box control.....

This is quite a simple procedure, and you should be able to do it yourself however if you run into any problems please post back for assistance.
 

PARSO

Registered User.
Local time
Today, 09:09
Joined
Dec 13, 2004
Messages
66
ok, does the new control have to be outside of the subform? and outside of the tab control box?

im guessin its 'TabCtl0.Pages.Item(0).SetFocus' that i edit?

but im unsure of what to...
ive seen Me.Text21.SetFocus about the forums
but it doesnt seem to work when i replace with the above.
 

PARSO

Registered User.
Local time
Today, 09:09
Joined
Dec 13, 2004
Messages
66
sorted!!

thanks Gzmo,
i needed to set the new control as the 1st item in Tab list.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:09
Joined
Jul 9, 2003
Messages
16,268
Yes, that's a good idea making the control you want the focus to go to the first one in the tab order.

You could also achieved the same thing like this:

If the controls name was "txtBoxTrapSetFocus"

Label6.Visible = False
txtBoxTrapSetFocus.SetFocus
subWindow1.Visible = False

Also notice that the subform is not actually on your tab, but it is inside a subform window. To follow the naming conventions, and to make your code more readable you should give this subform window its own name, and not rely on the name Automatically generated by MS Access, which is normally [and incorrectly] the name of the actual subform.

So you can see my code refers to the subform window:
subWindow1.Visible = False
 

Users who are viewing this thread

Top Bottom