Tab Change Passwords

R

Roger Bell

I have written an OnChange Event procedure in the properties of a Control Tab
as follows: This works fine for the Tabctrl Page 7, but does not work for the
Page 4.
Could anyone please tell me where I have gone wrong?
Thanks for any help

Private Sub TabCtl0_Change()
rctMask.Visible = True ' Mask page 7
If Me!TabCtl0 = 7 Then
If Not InputBox("Please Enter Password") = "roger" Then
Me!TabCtl0 = 0
MsgBox "Sorry, Incorrect Password"

Else
'show the tab page
rctMask.Visible = False
End If
rctMask1.Visible = True ' Mask page 4
If Me!TabCtl0 = 4 Then
If Not InputBox("Please Enter Password") = "roger" Then
Me!TabCtl0 = 0
MsgBox "Sorry, Incorrect Password"

Else
'show the tab page
rctMask1.Visible = False
End If

End If
End If
End Sub
 
T

tina

well, you don't say *how* it's gone wrong - is tab page 4 always hidden or
always visible? i assume that rctMask and rctMask1 are Rectangle controls
that you show/hide to cover/uncover the "contents" of the tab pages,
correct? so if the user is on tabpage 1, and moves to page 7, s/he must
enter the correct password to see what's on page 7; then if the user moves
to page 4, s/he must again enter the same password to see what's on page 4.
if the preceding is correct, then i don't see anything wrong with the code,
as far as it goes. are you sure rctMask1 is "sitting" on tab page 4, and not
behind the tab control? are you sure you're using the correct name of the
Rectangle control?

but suggest you give some thought to whether this is the best way to set up
your tab control. entering the same password over and over again, every time
they move to one of those two pages, is going to irritate your users to
death, hon.

as an alternative, you might try the following: get rid of the Rectangle
controls entirely. set the Visible property of tab pages 4 and 7 to False in
form Design view. then add a command button to the form, perhaps labeled
"Show All", or "Admin", or "Managers" - whatever is appropriate. add code to
the command button to show the hidden tab pages when the proper password is
provided, as

Private Sub cmdShow_Click()

If InputBox("Please enter password") = "roger" Then
Me!TabPage4.Visible = True
Me!TabPage7.Visible = True
Else
Msgbox "Sorry, incorrect password entered."
End If

End Sub

once the correct password is entered, those two tab pages are available to
the user as long as the form is open. each time the form is re-opened, the
pages are again hidden until the password is provided.

hth
 
R

Roger Bell

Thanks so much, Tina for your comprehensive reply.
The Password is requested when you go to Tabe Page 7 with no problems.
When you go to Tab Page 4, the Dialogue box for the Password does not appear
and the user goes to Page 4 which is covered by the Mask.

Tab page 4 is always visible. I have double checked the names of the
Rectangle Controls. The rctMask & rctMask1 are Rectangle controls. How would
I know for sure that rctMask1 is "sitting" on Tab Page 4? I assume it is, as
the fields are hidden when you click on this Tab. These Tabs are very rarely
used.
Is there anywhere else I may have gone wrong?
Thanks again for your valuable time
 
R

Roger Bell

Sorry, Tina
Please ignore my previous correspondence. I actually figured it out. I
needed 2 "End If" statements afer the first If.
Thanks again for your help
 
T

tina

ah, very good. are you compiling your VBA code as you write it, Roger? a
compile would have caught the missing End If immediately, so it's a good
habit to get into doing it. i compile my code every time i make a change,
usually before i move from the procedure, but always before i leave the VBA
Editor window.

hth
 
R

Roger Bell

I guess I have been a litlle slack in that regard, Tina
Thanks for your advice and all your patience and help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top