Command Button Password

R

Roger Bell

Could anyone tell me if it is possible to write some code into the "Onclick"
Event procedure that requires a password before the user can access a command
Button or Ctrl Tab?
Thanks for any help
 
T

tina

here's an example of one way to do it, as

Private Sub Command0_Click()

If InputBox("enter the password") = "something" Then
<do whatever the command button is supposed to do here>
Else
MsgBox "sorry, Charlie"
End If

End Sub

hth
 
R

Roger Bell

Thanks for that Tina. How can I add the code you supplied to the existing
procedure that currently reads as follows:

Private Sub ENTRE_WEEKLY_PLANNED_GIVING_Click()
On Error GoTo Err_ENTRE_WEEKLY_PLANNED_GIVING_Click

Dim stDocName As String

stDocName = "PLANNED GIVING WEEKLY"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_ENTRE_WEEKLY_PLANNED_GIVING_Click:
Exit Sub

Err_ENTRE_WEEKLY_PLANNED_GIVING_Click:
MsgBox Err.Description
Resume Exit_ENTRE_WEEKLY_PLANNED_GIVING_Click

End Sub
 
R

Ray Cacciatore

Roger,

Although the code provided by tina may appear to work, nothing stops users
from running the query called "PLANNED GIVING WEEKLY" from the database
window. The code behind this button simply calls a query and opens it on the
screen for users to edit.

If you open the database window and click on the Queries tab, you'll find a
query called "PLANNED GIVING WEEKLY", if you double-click it, it will open
for you to edit. Nothing stops users from opening it from there. I'm assuming
you took care of this "back door".

Ray
 
R

Roger Bell

Thanks for that Ray, understood, but can you tell me how I incorporate the
code Tina supplied into my existing "Onclick" event procedure as mentioned in
my previous reply. Also is it possible to have a similar procedure for
opening a specific page within a "Ctrl Tab"?

Thanks in advance
 
T

tina

How can I add the code you supplied to the existing
procedure

Private Sub ENTRE_WEEKLY_PLANNED_GIVING_Click()
On Error GoTo Err_ENTRE_WEEKLY_PLANNED_GIVING_Click

Dim stDocName As String

stDocName = "PLANNED GIVING WEEKLY"

If InputBox("enter the password") = "something" Then
DoCmd.OpenQuery stDocName, acNormal, acEdit
Else
MsgBox "sorry, Charlie"
End If

Exit_ENTRE_WEEKLY_PLANNED_GIVING_Click:
Exit Sub

Err_ENTRE_WEEKLY_PLANNED_GIVING_Click:
MsgBox Err.Description
Resume Exit_ENTRE_WEEKLY_PLANNED_GIVING_Click

End Sub

hth
 
T

tina

is it possible to have a similar procedure for
opening a specific page within a "Ctrl Tab"?

well, pages in a tab control don't "open" and "close", you merely navigate
from one to another. here's one way to stop the uninvited user from moving
to a "protected" tab, as

Private Sub TabCtl0_Change()

If Me!TabCtl0 = 1 Then
If Not InputBox("enter password") = "something" Then
Me!TabCtl0 = 0
MsgBox "sorry, Charlie"
End If
End If

End Sub

in the above example, the name of the tab control is TabCtl. each page in a
tab control has an index value - the first page's index value is 0, the
second page's value is 1, etc. the "value" of the tab control is the index
value of the currently selected tab page. so the above code says: if the
user clicks on the second tab page (which has an index value of 1), an input
box will open for the password to be entered; if the password is not
correct, the first tab page is selected instead; if the password IS correct,
the second tab page is selected as the user intended.

personally, i prefer to not show things to users that they can't actually
get at - it just causes frustration. i'd be more likely to hide the
"password-protected" page, and make it visible only when the correct
password is provided. to do that, you can use a command button, something
along the lines of

Private Sub Command0_Click()

If InputBox("enter the password") = "something" Then
Me!TabPageName.Visible = True
Else
MsgBox "sorry, Charlie"
End If

End Sub

hth
 
R

Roger Bell

Thanks again Tina. The Command button is working fine thanks to your
expertise. However, I tried the code in the Tab Control as follows:
("Onclick event")

Private Sub Planned_Giving_Information_Change()
If Me!Planned_Giving_Information = 6 Then
If Not InputBox("Please enter Password") = "roger" Then
Me!Householder_1 = 0
MsgBox "Sorry, Incorrect Password"
End If
End If
End Sub

where Planned_Giving_Information is the name and has the value of 6.
Householder_1 has the value of 0. Obviously, I have got it wrong & would
appreciate your guidance again and thank you for your patience.
 
R

Roger Bell

I actually found my Brain, which is rare, and got this to work. Thanks again
from the bottom of my heart for all your invaluable help. May all your days
be filled with Peace and Happiness.
 
T

tina

good job! and you're very welcome :)


Roger Bell said:
I actually found my Brain, which is rare, and got this to work. Thanks again
from the bottom of my heart for all your invaluable help. May all your days
be filled with Peace and Happiness.
 

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