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!

User Login Form

Status
Not open for further replies.

vlbridge

Technical User
Jun 23, 2011
39
0
0
US
I am trying to create a database that has a login form for users. I found some code that seems like it should work, but it's not working completely. The code is shown below. Everything seems to work except opening the password change form. The only things on the login form are a combobox that contains the names of the users and an unbound textbox for the users to enter their password. The combobox row source is the folllowing:

Code:
SELECT tblUser.UserID, [Lname] & ", " & [FName] AS Fullname, tblUser.Password, tblUser.PWReset, tblUser.AccessLevelID FROM tblUser ORDER BY tblUser.LName, tblUser.FName;

I would like the combobox to only show the Fullname column, but it is showing the Password column as well.

The code that I put into the AfterUpdate Event of the unbound textbox is below.

Code:
Private Sub txtPassword_AfterUpdate()

'Check that User is selected
If IsNull(Me.cboUser) Then
   MsgBox "You need to select a user!", vbCritical
   Me.cboUser.SetFocus
Else
   'Check for correct password
   If Me.txtPassword = Me.cboUser.Column(2) Then
       'Check if password needs to be reset
       If Me.cboUser.Column(4) Then
           DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
       End If
       DoCmd.OpenForm "frmMainMenu"
       Me.Visible = False
   Else
       MsgBox "Password does not match, please re-enter!", vboOkOnly
       Me.txtPassword = Null
       Me.txtPassword.SetFocus
   End If
End If
End Sub

Any help would be appreciated. I'm not well versed in VBA, which is why I am using someone else's code here. I am thinking the PWReset column is Column 3, not 4. However, it still isn't working when I change that to a 3. I think maybe I'm not understanding how it's set up. I put the PWReset in the table as a Yes/No field. I'm not sure if that's what it is supposed to be.

Thank you for your time.
 
Ok... I played with it a little more and I figured out the problem. The format of the combobox was not set up correctly. The column widths were set to 0";1";1". So, the password was showing in the combobox, but the PWReset field wasn't there at all, so the code couldn't find it. When I added the columns with a width of 0, it fixed the problem. I also had to change it to Column 3 instead of 4, as I suspected. I also made some changes to the Open Main Form lines because it was opening the main form on top of the change password form.

Thank you for your time anyway, but I figured it out. [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top