Results 1 to 4 of 4
  1. #1
    Robyn_P's Avatar
    Robyn_P is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2017
    Posts
    150

    close form event updating first record in table

    Hello,

    I have a weird one for you and I can't for the life of me work out what is going on.

    I have code in the form which checks whether a user's password needs to be updated and if so prompts the user to do this. Everything works fine until the last line of code which should just close the form (there is no code in the on close event of the form), instead it updates the data in the first record in the table to the new password entered for a different record. Below is the code, it's the docmd.close event that is causing the problem.



    Code:
    Private Sub cmdLogin_Click()
    
        Dim DashboardPic As String
        Dim rs As DAO.Recordset
    
    
        'Check that both a username and password have been added
        If IsNull(Me.txtPassword) Or IsNull(Me.cboUserName) Then
            MsgBox "You must enter both a username and password", vbOKOnly, "Missing Data"
            Exit Sub
        End If
        
        'Check the User's Password matches that in the users table
        If Me.txtPassword.Value <> DLookup("Password", "tblUsers", _
            "[ID]=" & Me.cboUserName.Value) Then
            
            ' Inform the user of an incorrect password and close
            MsgBox "Password Invalid.  Please try again", vbOKOnly, "Invalid Entry"
            Me.txtPassword.SetFocus
            Exit Sub
    
    
        End If
       
                         
        'Check if the change password check is true.  If so, make the user change their password
        If DLookup("changePassword", "tblUsers", "[ID]=" & Me.cboUserName.Value) = True Then
        
            Password = InputBox("Your password must be changed", "Set password")
            
            'Update the password
            Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblUsers WHERE [ID]=" & Me.cboUserName.Value)
            rs.Edit
            rs("Password") = Password
            rs("changePassword") = False
            rs.Update
            rs.Close
            Set rs = Nothing
        
        End If
            
        ' Open frmDashboard The On Open even of frmDashboard takes the userID from
        ' This form and saves it for furture reference on frmDashboard
        DoCmd.OpenForm "frmDashboard"
        
        ' Close this form
          DoCmd.Close acForm, "frmLogin", acSaveYes
    
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Is the form bound?
    Appears to be no need for it to be bound.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Robyn_P's Avatar
    Robyn_P is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2017
    Posts
    150
    Quote Originally Posted by Welshgasman View Post
    Is the form bound?
    Appears to be no need for it to be bound.
    Thank-you! Yes the form was bound for no reason. I removed that any it's not working correctly.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I removed that any it's not working correctly.
    I am assuming that should be

    I removed that and it's now working correctly. :-)
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 04-20-2022, 03:27 AM
  2. Replies: 9
    Last Post: 05-24-2021, 06:29 AM
  3. Replies: 1
    Last Post: 11-28-2017, 07:28 AM
  4. Replies: 6
    Last Post: 06-05-2015, 04:02 PM
  5. Replies: 9
    Last Post: 12-25-2014, 12:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums