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 Form for Multiple Objects HELP! 1

Status
Not open for further replies.

DarkOne72

Technical User
Jun 14, 2002
208
US
Hello All --
I need some assistance if possible. I am needing help with a password form I have. I have a table named PasswordTable with a single password in it and a password form named AdminForm. On the form I have an unbound text box named PasswordTextBox , a close button and a Submit button. I can get the code to work when I just want to open 1 form by using the following code:
Code:
Private Sub Submit_Click()
If DLookup("AdminPassword", "PasswordTable") = Me.PasswordTextBox Then
  DoCmd.Close
  DoCmd.OpenForm "Form_to_Open", acNormal
Else
  MsgBox "Incorrect Password! Try again!"
  PasswordTextBox.SetFocus
  Me.PasswordTextBox = ""
End If
End Sub

What I need to happen is be able to call the password form up from multiple buttons on click and open up that form based on the button that was clicked. For instance; If I click view report button it opens the password form and if password is successfully entered then it closes the password form then opens the report. If I click on a different button that would open a different form it too will call the password form and if the password i s successfully entered it would close the password form and then open up what was intended. In any even if the user closes or cancels the password form without putting in the correct password it will not open up anything that was clicked initially.

I am not sure how to go about this if someone could please assist me.

Thanks!
 
So in your application you ask the user several times for the same password? I would go mad if I would be your user. I can understand entering the password once, but after that - WHY?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Well I don't know any other way to restrict just certain forms for the just the admin. I do not want a log in form when the database starts up since the one person who will be administering the db and will use those locked forms will only be on every other day and not use all restricted forms every day etc. By all means if you know something simpler I am open to suggestions.

Thanks for the reply.
 
Well, I want to make sure that it isn't remembered when he walks away and allows others to use the db. Also, I'm not sure how the best way to accomplish this is.
 
It would really help if you provided greater details about your environment and requirements from the beginning.

You can use OpenArgs to send in the "form/report to open" when opening the password form. Then your code might look something like:

Code:
Private Sub Submit_Click()
If Me.OpenArgs & "" <> "" Then
  If DLookup("AdminPassword", "PasswordTable") = Me.PasswordTextBox Then
    DoCmd.Close
    DoCmd.OpenForm Me.OpenArgs, acNormal
   Else
    MsgBox "Incorrect Password! Try again!"
    PasswordTextBox.SetFocus
    Me.PasswordTextBox = ""
  End If
End If
End Sub
You could add other error trapping to make sure there is a form with the supplied name etc.

Duane
Hook'D on Access
MS Access MVP
 
To simplify the amount of code and the logic, you may consider splitting the database and having two different front ends. A User front end and a Admin front end. The Admin front end would have more forms and capabilities. Since this is a multiuser application it should be split regardless. The admin person would then just need a Password to get into the admin db, and does not "walk away" and allow others to use it.
 
This is just my guess, but when you start your application, you start with some Main Menu? So on this ‘staring’ form you may have all command buttons for all Users to access (no password required) and you may have just one command button: “Admin” which would lead you to another menu form just for Admin. And the “Admin” command button would require a password to go to Admin menu where you would have all other ways to access what admin can do. One password provided once.

As far as: “when he walks away and allows others to use the db” What do you think happens when FBI or CIA Director accesses some top secret information and steps away from his desk without either logging out or locking his computer securing his access – and janitor enters his office and starts sniffing around in top secrets?
By-by Director.[wavey][wavey2]

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
I do have a menu but it incorporates the admin section and reports section as well. I really don't want two menus pages.
Dhookom, I tried the code but i am not sure how to get the args to work properly.
Basically, I have a menu with buttons on it in sections and if you go to certain buttons it will ask for a password which is where i am stuck. I can get it to work with the inputbox but i wanted it to work via form for asterisk and a more pleasant look and be able to use that one password form and table to open up the desired report or form.
I don't want to have a login form or an invisible form as it will always be open if he didn't close the hidden form.


I guess it isn't possible to do what i need..unless any other ideas come about.
 
I guess it isn't possible to do what i need..unless any other ideas come about
It is completely possible, I can think of about 10 different ways to do it. Everyone sets up applications where certain users have access to certain capabilities. You are just not very clear, on how you want it to work.
 
I dont know how much more clear i can be...but I will try again.
The database launches and it has a menu with 8 buttons on it 5 of the buttons i want to be password protected; if you click on one of those then a popup password form (which I have AdminForm) and if you type in the correct password it will close the password form and open up the form or report to which that button is supposed to open. I have the table with the password in and the AdminForm pulls from that to verify it is correct. If the password you typed in is incorrect it won't open the form or report.

That's pretty much it. I don't want to have 2 menus and I don't want an open invisible form.

I hope this helps on being clear, but really it is basic I just don't know how to do it
 
Another idea – and that’s what I do in my application.
You have one user as admin and you want him to access some data (some command buttons), and other users are kept away from it. Fine.
Instead of a table with a password, I would have a table with Admin user name(s). You can easily detect who is accessing your application (user’s Windows login name) and based on that information make Admin’s command buttons either visible or not visible. No password required, even once.

You could easily add more user names to the table to give Admin privileges to more people, and you can easily remove any name from Admin access. Sometimes I give this ability to one ‘main’ Admin person and let him decide who should/should not have access to some parts of the app.

You would keep your form(s) the way you have it now.

Would that work for you?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Yeah, that sounds awesome and would work perfectly IF they logged into the computer with their own credentials but as it is now there is only 1 login and thats the way they want it..I know stupid but, i didn't make that command decision [mad]
 
OK, then use my previous idea, similar to the one you just liked:
“8 buttons on it 5 of the buttons i want to be password protected” – at the beginning ask for the password once. If correct password is provided – make your 5 buttons visible. Otherwise, if password is wrong or Cancel is clicked, keep 5 buttons Visible = False (default setting)


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Darkone72,

The command button code to open the password form would look something like:

Code:
Dim strFormName as String
strFormName = "frmMyAdminForm1"
DoCmd.OpenForm "AdminForm" ,acNormal,,,,acDialog ,strFormName

Then use code in the AdminForm as I suggested earlier.

Duane
Hook'D on Access
MS Access MVP
 
dhookom,

I tried your suggestion and put everything in place but i get an invalid procedure call or argument error run-time error '5' when i type in the correct password from the admin form (where you type in the password)
thanks
 
I have a form within an application, the users can only log into the system if there NTlogin is in a table called Permissions, this also has a permission level, User or Admin.

Certain buttons are all set to Visible = False

On the Form Load event they are then turned on by this
Code:
    UserName = DLookup("[ID]", "dbo_User", "[login] = '" & fOSUserName & "'")
    Permissions = DLookup("[Permissions]", "dbo_User", "[login] = '" & fOSUserName & "'")
If Permissions = "Admin" Then but_Amend.Visible = True

'Clever boy...'
 
its what you had earlier; the textbox is labeled whats below as well as the table ..wasn't sure on the
Code:
DoCMD.Openform Me.OpenArgs, acNormal though
Code:
If Me.OpenArgs & "" <> "" Then
  If DLookup("AdminPassword", "PasswordTable") = Me.PasswordTextBox Then
    DoCmd.Close
    DoCmd.OpenForm Me.OpenArgs, acNormal
   Else
    MsgBox "Incorrect Password! Try again!"
    PasswordTextBox.SetFocus
    Me.PasswordTextBox = ""
  End If
End If
 
jeffwest21, good idea with your approach, but DarkOne72 said: "there is only 1 login and thats the way they want it" :-(

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top