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!

Create logon to Access Database 1

Status
Not open for further replies.

PleaseGiveHelp

Programmer
Oct 29, 2002
131
US
I want to create a form that will act as the logon (thus main startup page) to my access database. I want the form to search the users table (based on the username and password entered) to make sure the user is valid before letting in to the database (if not valid, error message). Its been a while since I last used Access so I'm drawing a blank. How do I start? I've created the table that contains the usernames and passwords...HELP!
 
You build a table of 'good' names and check that with the name the user enters. You might want to check some other stuff. I think YourDatedase.lbm or something is a list or all the users logged in on that prg. Perhaps you might Open it Read_Only and see who is on it.

Rollie
 
Ok so I built the table, etc...then I created a login form...behind the form I have this code:
Private Sub cmd_OK_Click()

Dim tmpID As String

' Check to see if Login box is empty
If IsNull(Me.cmb_Login) Or Me.cmb_Login = "" Then
MsgBox "You must choose a User Name.", vbOKOnly, "Required Data"
Me.cmb_Login.SetFocus
Exit Sub
End If

' Check to see if Password box is empty
If IsNull(Me.txt_Pass) Or Me.txt_Pass = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txt_Pass.SetFocus
Exit Sub
End If

' Check to see if Password entered matches password in Logon table
If Me.txt_Pass.Value = DLookup("UPassword", "Logon", "[UName]= " & Me.cmb_Login.Value) Then

tmpID = Me.cmb_Login.Value
MyID = tmpID

' Close logon form and open main form
DoCmd.Close acForm, "Logon", acSaveNo
DoCmd.OpenForm "Account"
End If

End Sub

HOWEVER it keeps errroring out at: If Me.txt_Pass.Value = DLookup("UPassword", "Logon", "[UName]= " & Me.cmb_Login.Value) Then...saying 'The object doesn't contain the Automation object 'admin''.
I don't understand where I am wrong...HELP!
 
Change the offending line to read as follows

If Me.txt_Pass.Value = DLookup("UPassword", "Logon", "[UName]= '" & Me.cmb_Login.Value & "'") Then...

Notice the single quotes after the '=' and the "'" group at the end.

This is a general rule. If you are searching for a text value, the criteria has to quote the thing you're looking for.

 
I was able to get this to work great with one exception, nothing happens if the wrong username and/or password are entered. The login screen doesn't even blink. Any ideas?

Great post by the way! Thanks for submitting it.
 
Veronica:
Just continue the If clause with an Else:


DoCmd.OpenForm "Account"
Else
MsgBox "Username does not match the password"
End If

Now...seriously:
1. If not backed up by Access built-in security, this table of users and passwords is just a little joke and data in it can be viewed/changed/deleted by anyone. Try linking that table to a brand new database. The 'Input Mask' property can be changed in linked tables, so passwords are revealed.
If your database contains sensitive information, take your time to dive into Security.

2. Password checking should be case sensitive. Either use StrComp function or change Option Compare Database to Option Compare Binary

Sorry to spoil the joy...but better late than never...

HTH




[pipe]
Daniel Vlas
Systems Consultant

 
Thanks. That's perfect!

Veronica

ps: I am not really worried about security at this point. This will serve as a scare to those that have no business opening it in the first place. There is no real security issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top