Creating a Multi-User Login

S

swlaw

I am trying to create a multi-user login. When I create this in a 'sample'
database it works fine. I create three forms and one login form with the
appropriate VB code. No problems, I can add as many users as I want in the
code.

The problem is when I try to create the exact same login, same code, in my
actual database, for some reason it does not work. I checked all the names
and so on but cannot seem to get it to work.

Any suggestions for something I may be doing wrong.
Please help. :)

This a portion of the code:

Private Sub Login_Current()
Username.SetFocus
If Username = "user1" And Password = "user1" Then
MsgBox "Access Granted", vbInformation, "JMS"
MsgBox "Welcome", vbInformation, "JMS"
DoCmd.Close
DoCmd.OpenForm "Switchboard"
Else
MsgBox "Please re-enter your Username and Password."
End If
End Sub
 
P

Philip Herlihy

"Does not work" can mean an awful lot of things. Forgive me for being lazy,
but my response to this is very like one I posted just a couple of days ago.
If you'd like to have a look here:
http://bit.ly/7ixMqh
.... you may find it leads you to a solution.

Phil, London
 
S

swlaw

Does not work, means that when I log in it is suppose to go to a form. Seems
pretty simple but I am having a hard time? Any suggestions.
 
P

Philip Herlihy

I wonder if the DoCmd.Close is closing the form whose module may turn out to
contain the code you're running, so it never gets to the DoCmd.OpenForm.

However, without using error handling code and setting breakpoints I'm only
guessing. My suggestion was and is that you add error-handling, learn how
to use breakpoints and how to step through code. Not hard, and all there in
Help!

Phil
 
K

KenSheridan via AccessMonster.com

You don't say where this procedure is being called from, but I'd assume its
from the Click event procedure of a button on the form as it requires both
controls to have values, which really rules out it being called from their
AfterUpdate event procedures as there can be no guarantee as to the order in
which the user enters the values.

I'd suggest creating a couple of functions in the login form's module:

Private AssessLogin(varUser, varPassword)

' do nothing unless both values have been entered
If Not IsNull(varUser) And Not IsNull(varPassword) Then
If GoodLogin(varUser, varPassword) Then
MsgBox "Access Granted", vbInformation, "JMS"
MsgBox "Welcome", vbInformation, "JMS"
' open switchboard and close this form
DoCmd.OpenForm "Switchboard"
DoCmd.Close acForm, Me.Name
Else
MsgBox "Please re-enter your Username and Password.", _
vbExclamation, "Invalid log-in."
End If
End If

End Function

Private GoodLogin(strUser As String, strPassword As String) As Boolean

Select Case strUser
Case "User1"
GoodLogin = (strPassword = "Password1")
Case "User2"
GoodLogin = (strPassword = "Password2")
Case "User3"
GoodLogin = (strPassword = "Password3")
Case Else
GoodLogin = False
End Select

End Function

You can then call the AssessLogin function as the AfterUpdate event property
of both the UserName and Password controls, or as the OnClick event property
of a separate 'confirm' button by entering the following as the event
property in the control's properties sheet:

=AssessLogin([UserName], [Password])

Ken Sheridan
Stafford, England
 

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