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!

Creating a User Login Form for capture of user in forms

Status
Not open for further replies.

Hulm1

Technical User
Mar 11, 2008
100
GB
I have read the the faq181-74 and this exactly what I want to do. I want to create a simple user login form with password referring to a table with: UserID; Username; and Userpassword.

However, I cannot get one to work correctly and anyway, how does access know who the currentuser() (as per the above faq) actually is? Seems to me that some of these forms that I have seen on other forums simply check a password and let you in. I hope I am explaining myself well here? In other words how to I make my user login form register that the user is the "currentuser" as per the faq???

I would prefer my own login form rather than using the Windows user.

Help gratefully appreciated!
 
If you are using Access 2003 and below, you can set up a workgroup. You can then also implement security on forms, reports, etc. if you want.

You can use workgroups in Access 2007 to login, but it doesn't implement security. I created a login form where the username is autopopulated with their network name and then they simply enter their password. I have a table that defines who is allowed access to the system. So, when the user logs in, I check to see if they are listed in the table (based on their network name). You can use environ("username") to get the user's network name, but I believe that is being phased out in later version of office.
 
Thanks for that. However, I really don't want to use the PC or network login name. I want to use a login to access which requires the user to either enter their name, or preferably select themselves from a combo box and then enter their password. The form needs to reference their password in the User Table and then allow access.

I understand about using the network login and Environ but wanted to use the above login process. But I'm stuck!
 
You might look at implementing User Level Security but it isn't for beginners. It can get fairly involved. Search google for resources and white papers on how to implement this. I generally figure it's more work than it is worth.

Duane
Hook'D on Access
MS Access MVP
 
This thread thread705-978122 will explain how to setup User Level Security.
 
The following is probably along the lines of what you are looking for. A login form contains a combo box which lists out names. An After Update event of the combo box turns a password text box visible. The user supplies a password. If the password matches the password stored in the table, the main form (in this case a switchboard) opens, filling in the user's name, times opened and other information.

Code:

Private Sub txtPwd_AfterUpdate()

Dim pwdID As Long
Dim Pwd As String
Dim EnterPwd As String
Dim TimeUsed As Long

On Error GoTo Err_frmErr

pwdID = (Me.cboDepartment.Column(0))

Pwd = DLookup("[password]", "tblPsn", "val([psnID])= '" & pwdID & "'")

EnterPwd = Me.txtPwd

If EnterPwd <> Pwd Then

Me.txtCounter = Me.txtCounter + 1

MsgBox "Incorrect Password", vbExclamation, "Wrong Password"

End If

If Me.txtCounter > 3 Then

MsgBox "That was your third try. Please talk to your administrator about login privaleges.", vbOKOnly, "Invalid Password"

Me.txtCounter = 0

DoCmd.Quit acQuitSaveNone


Else

Me.cboDepartment.SetFocus
Me.txtPwd.DefaultValue = Empty
Me.txtPwd.SetFocus

End If

If EnterPwd = Pwd Then

Me.txtCounter = 0

DoCmd.OpenForm "switchboard", acNormal
Forms!switchboard.lblCurrentUser.Caption = Me.cboDepartment.Column(1)

TimeUsed = Nz(DLookup("[timesUsed]", "tblPsn", "val([PsnID])= '" & pwdID & "'") + 1, 0)

DoCmd.SetWarnings False

DoCmd.RunSQL "UPDATE tblPsn SET tblPsn.timesUsed = '" & TimeUsed & "'WHERE val(tblPsn.psnID) = '" & pwdID & "'; "

DoCmd.SetWarnings True

Forms!switchboard.lblTimesUsed.Caption = DLookup("[timesUsed]", "tblPsn", "val([psnID])= '" & pwdID & "'")
Forms!switchboard.txtUserID = DLookup("[psnID]", "tblPsn", "val([psnID])= '" & pwdID & "'")

Pwd = Empty
Me.cboDepartment.DefaultValue = Empty

Me.Visible = False

End If

End Sub
 
Thank you very much for this. Sorry for delay. I cannot be anything but part time on this as I run my Company! So I dip in and out. I will come back to this and have a go with it in a day or so. I really appreciate your help. It does look like what I seeking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top