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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Password to Form 4

Status
Not open for further replies.

tylerwork

Technical User
Aug 20, 2002
31
0
0
US
How can I add a password to a particular form when it's opened from a switchboard?
 
Can you explain more ? Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
yeah, i want only people with a password to be able to open a form. i have a switchboard with 4 buttons - each one opens a particular form, and i want only one of those buttons to be password-protected. the administration button. how can I do this?

 
Ok, Try this
1. You need to popup a Password form, when user clicks Password protected button
2. Your pssword form consists 3 controls one for User name(if you need),another for password and a command button.
3. In Password Form Command Button Click event Check user authentication then allow to see info.
In Command Button Click event
a) Check for PWD In database
2) If password matches then open a new form with info, if not popup a message and close the password form

Hope this helps Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
how do i make a password form? that's where I'm getting stuck. Thanks!
 
1. Add a Form to your database say Password
2. Add 4 Controls 1.txtUserName,2.txtPassword,3.CmdOk and 4.cmdCancel
3.Go to txtPassword textbox Properties.Click on Data Tab and Set InputMask to Password
4.In cmdOk Click event Check Password in Database and
if it is a valid password then show detail form.
DoCmd.OpenForm "Detail Form"
else show a message Incorrect Password message and close the form.
5.in CmdCancel click event close the form
DoCmd.Close A_FORM, "Password"
Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
cool everything is good so far.

how do i make it check the password in the database?

 
1. you need to create a table say Security with minimum 3 fields.
a. UserId Number/Text (Key Field)
b. UseName Text(50)
c. Password Text(50)
If you want you can add any other Info Like Secuty Level etc...

2.In CmdOk Click Event you need to write a SQL Statement like

Dim Curdb As Database, SQLStmt As String, SecTB As Recordset

Set Curdb = CurrentDb() 'If your table and form are in same database other wise change it

SQLStmt = "SELECT * FROM [Security] WHERE [UserName] = '" & Trim("" & Me![txtUserName]) & "'"
SQLStmt = SQLStmt & " [Password] = '" & Trim("" & Me![txtPassword]) & "'"
Set SecTB = Curdb.OpenRecordset(SQLStmt, DB_OPEN_DYNASET)
If SecTB.EOF Then
MsgBox "Logon ID or Password not found!", 16, "Incorrect Logon Information"
SecTB.Close
Exit Sub
End If

SecTB.Close
DoCmd.OpenForm "Detail Form" Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
Everythign is almost working great - but I am getting this error when I run it:

(i have "lou" and "lou" as username and password)

Run-Time Error '3075':
Syntax error (missing operator) in query expression '[username] = 'Lou' [password] == 'lou".
 
Sorry, SQLStmt was Wrong.Please Change Like this

SQLStmt = "SELECT * FROM [Security] WHERE [UserName] = '" & Trim("" & Me![txtUserName]) & "'"
SQLStmt = SQLStmt & " AND [Password] = '" & Trim("" & Me![txtPassword]) & "'"


Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
Great solution. Though I am having two problems. One is that even after opening the form, password form stays open beneath which should be closed and secondly, since I am calling my form based on a parameter query, when I cancel the parameter I get very unsightly message that the action was canceled. I wonder if you could add additional couple of lines to this code.

Cheers
 
Ok,

1.Please Include DoCmd.Close A_FORM, "Password" Immediatly after DoCmd.OpenForm "Detail Form" .
Then your code in cmdOk Click event Looks like
DoCmd.OpenForm "Detail Form"
DoCmd.Close A_FORM, "Password"
Forms![Detail Form].Setfocus
2. Can you post more details about this ? Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
If you have workgroup security set up on your database you could simply not give permissions to that form for certain folks.
 
emergplan: You must set a reference to Microsoft DAO 3.6. Object library to run that piece of code.
Before doing that, fully qualify the variable:
Dim curdb As DAO.Database
If you don't want to set the reference, you will have to change the code to ADO model (curdb will be a Connection object instead of Database, and SecTB will be an ADODB.Recordset instead of DAO.Recordset):

Dim curdb As ADODB.Connection
Dim SecTB As New ADODB.Recordset
Set curdb = CurrentProject.Connection
...
SecTB.Open SQLStmt, curdb, adOpenDynamic, adLockOptimistic


Good luck [pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top