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

Passwords? company access? Different users?

Status
Not open for further replies.

NewfieSarah

Programmer
Feb 7, 2005
147
0
0
CA
I was wondering if I can set up a form to have user name and password, check in a table, and allow a form to be opened of they are allowed and display a message if they are not. can anyone hlep?
 
have you considered using the built in database security features?

--------------------
Procrastinate Now!
 
On top of Crowleys post, what I do is pick up the logged on user to the pc, check it up in a user table. if they are recorded there as a valid admin, then I allow them loads of access to buttons and forms. if they are there but not as ad admin/OR their name isnt in the table at all, I lock everything up!

You may want to consider this as an option.
 
This is what I have. I remember finding this code on some website. I slightly modified to meet my needs.

You will need a table with username and password stored and a form with username and paswword textboxes plus a command button.

I placed this code on the click event of the command button.

Option Compare Database
Private intLogonAttempts As Integer
Private Sub cmd_Login_Click()



'Check to see if data is entered into the UserName combo box

If IsNull(Me.txt_UserName) Or Me.txt_UserName = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.txt_UserName.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txt_Password) Or Me.txt_Password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txt_Password.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this matches value chosen in combo box

If Me.txt_Password.Value = DLookup("PASSWORD", "tbl_Employees", "[USERNAME]='" & Me.txt_UserName.Value & "'") Then
PubUserName = Me.txt_UserName
lngMyEmpID = Me.txt_UserName.Value

'Close logon form and open splash screen

DoCmd.close acForm, "frm_Login", acSaveNo
DoCmd.OpenForm "Switchboard"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txt_Password.SetFocus
End If



'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub

 
Thanks for the code "genaccess" however,I am getting an error for PubUserName and lngMyEmpID so I dimed them as strings and that is fine. Now the ID is not being checked with what is in the database?? and I need it to look through the databse and just use the first one, which it is doing for the password.thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top