Put password to open a tab in Access 2010 (1 Viewer)

emsadoon

Registered User.
Local time
Today, 00:17
Joined
Jun 6, 2013
Messages
83
Is it possible to put password for a tab in Access 2010?
 

michaeljryan78

Registered User.
Local time
Yesterday, 23:17
Joined
Feb 2, 2011
Messages
165
You can achieve a "feel" of this by setting the visible property to false and have a command button to unhide it:

Code:
Dim strPass As String
Dim strverify As String
strPass = "password"
strverify = InputBox("what is the password to view the tab?")
If strPass <> strverify Then
    Me.Page1.SetFocus
    Me.Page2.Visible = False
Else
    Me.Page2.SetFocus
    Me.Page2.Visible = True
End If

that may be one way, but there could be many others.
 

emsadoon

Registered User.
Local time
Today, 00:17
Joined
Jun 6, 2013
Messages
83
Thanks michaeljryan78 . I used your code and it worked. But I want to change your code a little and put on Click event of the tab. I want when I click on the tab, the password page pops up, before loading the form. The code I have so far is

Code:
Private Sub NavigationButton63_Click()
Dim strPass As String
Dim strverify As String
strPass = "password"
strverify = InputBox("what is the password to view the tab?")
If strPass <> strverify Then
    
    Exit Sub
   
Else
    Me.NavigationSubform.SetFocus
    
    DoCmd.OpenForm "Distribution List Form", acNormal
End If
End Sub

This code does not prevent the tab from opening the form before entering the password. Can you suggest me how I can fix this?
 

emsadoon

Registered User.
Local time
Today, 00:17
Joined
Jun 6, 2013
Messages
83
Since I am working on a navigation form with the tab across the top, If I set the visibility of a sub-form (the form that will be opened once the tap is clicked) to "no". Then the entire sub-forms will be invisible.
 

emsadoon

Registered User.
Local time
Today, 00:17
Joined
Jun 6, 2013
Messages
83
I tried to put the code on "on focus" event, it actually works. But when I press a wrong password and then click ok , it opens the form that should be opened.
 

nanscombe

Registered User.
Local time
Today, 04:17
Joined
Nov 12, 2011
Messages
1,082
Just bringing this back onto your post. :)

Thanks Nigel. I am actually using your way to create one for myself. But, I do not know how to call my navigation buttons.I have navigation buttons with names of NavigationButton1,NavigationButton2,.... . Furthermore, each of this navigation button targets to an existing form outside the navigation form. I cannot find something like "maintab" in my navigation form. Here is my code:

Code:
Private Sub cmdLogin_Click()
Dim intPages As Integer

For intPages = 1 To Me.NavigationButton.Pages.Count - 1
    Me.NavigationButton.Pages(intPages).Visible = (Me.txtPassword & vbNullString = "abc")
Next intPages

If Me.NavigationButton.Pages(1).Visible Then Me.NavigationButton = 1
End Sub

I think you are using a series of Command Buttons rather than a single Tab Control. If so then

Code:
Private Sub cmdLogin_Click()
Dim intControls As Integer, maxControls as Integer

  maxControls = (Largest number of your Command Buttons)

  For intControls = 1 To maxControls
' If your first controls are numbered 1 - 9, which I suspect they are
    Me.Controls("NavigationButton" & intControl).Visible = (Me.txtPassword & vbNullString = "abc")

' If your first controls are numbered 01 - 09
'    Me.Controls("NavigationButton" & Format(intControl, "00")).Visible = (Me.txtPassword & vbNullString = "abc")

  Next intControls

  If Me.NavigationButton1.Visible Then Me.NavigationButton1.Setfocus
End Sub

This may give problems if some buttons in the sequence don't exist but you could try this first.
 

emsadoon

Registered User.
Local time
Today, 00:17
Joined
Jun 6, 2013
Messages
83
Thanks. I used this code
Code:
Private Sub cmdLogin_Click()
Dim intControls As Integer, maxControls As Integer

  maxControls = 6

  For intControls = 1 To maxControls
' If your first controls are numbered 1 - 9, which I suspect they are
    'Me.Controls("NavigationButton" & intControl).Visible = (Me.txtPassword & vbNullString = "abc")

' If your first controls are numbered 01 - 09
 Me.Controls("NavigationButton" & Format(intControl, "00")).Visible = (Me.txtPassword & vbNullString = "abc")

  Next intControls

  If Me.NavigationButton01.Visible Then Me.NavigationButton01.SetFocus
End Sub

But I get this error :"complile error : method or data member not found!", I guess it cannot recognize Me.NavigationButton
 

nanscombe

Registered User.
Local time
Today, 04:17
Joined
Nov 12, 2011
Messages
1,082
Is your button NavigationButton01 or Me.NavigationButton1?

And which line gives the error?
 

emsadoon

Registered User.
Local time
Today, 00:17
Joined
Jun 6, 2013
Messages
83
Actually I diactivated the following line
Code:
 If Me.NavigationButton01.Visible Then Me.NavigationButton01.SetFocus
, and the error said "MS Access cannot find the field 'NavigationButton' referred to in your expression". The button names are NavigationButton01,02,..,06 .
 

emsadoon

Registered User.
Local time
Today, 00:17
Joined
Jun 6, 2013
Messages
83
I actually find out that
Code:
[Forms]![Navigation Form]![NavigationButton01].Visible
works instead of
Code:
Me!NavigationButton01.Visible
or
Code:
Me.Controls("NavigationButtons01").Visible

But now when I replace
Code:
Me.Controls("NavigationButton" & Format(intControl, "00")).Visible = (Me.txtPassword & vbNullString = "abc")
with
Code:
[Forms]![Navigation Form]!["NavigationButton" & Format(intControl, "00")].Visible = (Me.txtPassword & vbNullString = "abc")
, it does not work. Do you know how I can fix it?
 

nanscombe

Registered User.
Local time
Today, 04:17
Joined
Nov 12, 2011
Messages
1,082
Well, here' a demo of it working anyway.

I did spot a typo of mine, intControl instead of intControls, which wouldn't have helped. :eek:

Code:
Private Sub cmdLogin_Click()
Dim intControls As Integer, maxControls As Integer

  maxControls = 6

  For intControls = 1 To maxControls

' If your first controls are numbered 01 - 09
 Me.Controls("NavigationButton" & Format(intControl[COLOR="Red"]s[/COLOR], "00")).Visible = (Me.txtPassword & vbNullString = "abc")

  Next intControls

  If Me.NavigationButton01.Visible Then Me.NavigationButton01.SetFocus
End Sub
 

Attachments

  • emsadoon_001.zip
    13.6 KB · Views: 306

emsadoon

Registered User.
Local time
Today, 00:17
Joined
Jun 6, 2013
Messages
83
Thanks a lot Nigel for making the Demo for me.
 

Users who are viewing this thread

Top Bottom