Results 1 to 10 of 10
  1. #1
    Mclaren is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Location
    Johannesburg
    Posts
    164

    runtime error 2110

    I have 3 controls n a form. two text boxes and a button:


    • txt_Username
    • txt_Password
    • cmd_Login


    After the following code runs, if the password is incorrect, a private function (Reset_Fields) clears the text boxes. after the text boxes are cleared, i want the txt_Username to be brought back into focus, however, I am having an issue setting focus and i get a runtime 2110 error.

    Code:
    Private Sub cmd_Login_Click()
    
        If IsNull(DLookup("[Username]", "[tbl_Contacts]", "[UserName]='" & Me![txt_UserName] & "'")) Then
        vDBUserName = ""
        Else
        vDBUserName = Me.txt_UserName
        End If
    
        If IsNull(DLookup("[UserPassword]", "[tbl_Contacts]", "[UserName]='" & Me![txt_UserName] & "'")) Then
        vDBUserPassword = ""
        Else
        vbDBUserPassword = Me.txt_Password
        End If
           
        If Me.txt_Password.Value = DLookup("[UserPassword]", "[tbl_Contacts]", "[UserName]='" & Me![txt_UserName] & "'") Then
            MsgBox "it works.  ", vbOKOnly, "all working!"
            Else
            Reset_Fields
            Me.txt_Username.setfocus
        End If
    
    End Sub
    what am i doing wrong ?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Could mean:

    Not the correct name of textbox (I suspect this most likely because VBA did not correct setfocus to SetFocus)

    Textbox not enabled or visible

    The form doesn't have focus
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    One other question - what is the code for your Reset_Fields procedure?

  4. #4
    Mclaren is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Location
    Johannesburg
    Posts
    164
    I hand typed the line of code on the forum, thats why VBA did not correct setfocus to SetFocus.

    My code is as follows for the reset_field function
    Code:
    Private Function Reset_Fields()
    me.lbl_Error_message.visible = true
    me.txt_Username = ""
    me.txt_UserPassword = ""
    End Function
    i don't at any point set the txt_Username to :
    .Enabled = false
    .Visible = false

    The Reset_Fields function just clears any data in the relevant txt box fields and sets a labels property to visible.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I am at a loss, code looks good to me. Would have to analyze the project if you want to attach to post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Mclaren is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Location
    Johannesburg
    Posts
    164
    will do, but only later, i don't have my DB with me right now.

  7. #7
    Mclaren is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Location
    Johannesburg
    Posts
    164
    I have attached the db as requested

  8. #8
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    The problem is your Lost focus event of the password text box. Comment out that and you are fine. The problem appears to be that it is hitting that twice and then the second call happens but the focus is already on the text box so it can't set the focus again.

  9. #9
    Mclaren is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Location
    Johannesburg
    Posts
    164
    THANKS, i will have a look see when i get home tonite.

  10. #10
    Mclaren is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Location
    Johannesburg
    Posts
    164
    thanks, sorted

    my code for my login screen:
    Code:
    Option Compare Database
    Option Explicit
    
    Dim intMaxLogonAttempts As Integer
    Dim intContactID As Integer
    Dim intStoredLogonAttempts As Integer
    
    
    Private Sub Form_Open(Cancel As Integer)
        vLoginAttempts = 0
        Me.Caption = "Login"
        Me.txt_UserName.SetFocus
        Me.lbl_Login_Error.Visible = False
        Me.lbl_Click_Here.Visible = False
        Me.lbl_Login_Count.Visible = False
        
    End Sub
    
    
    Private Sub cmd_Login_Click()
    
        intMaxLogonAttempts = DLookup("[Value]", "tbl_DB_Properties", "[Propertyid] = 4")
    
        If IsNull(DLookup("[Username]", "[tbl_Contacts]", "[UserName]='" & Me![txt_UserName] & "'")) Then
            vDBUserName = ""
        Else
            vDBUserName = Me.txt_UserName
            intContactID = (DLookup("[contactID]", "[tbl_Contacts]", "[UserName]='" & Me![txt_UserName] & "'"))
            intStoredLogonAttempts = (DLookup("[logonAttempts]", "[tbl_Contacts]", "[UserName]='" & Me![txt_UserName] & "'"))
            vLoginAttempts = intStoredLogonAttempts
        End If
    
        If IsNull(DLookup("[UserPassword]", "[tbl_Contacts]", "[UserName]='" & Me![txt_UserName] & "'")) Then
            vDBUserPassword = ""
        Else
            vDBUserPassword = Me.txt_Password
        End If
           
        If Me.txt_Password.Value = DLookup("[UserPassword]", "[tbl_Contacts]", "[UserName]='" & Me![txt_UserName] & "'") Then
            vLoginAttempts = 0
            updateField "tbl_Contacts", "LogonAttempts", "UserName", vDBUserName, vLoginAttempts
            MsgBox "it works.  ", vbOKOnly, "all working!"
            DoCmd.Close acForm, "frm_Login_Dialog", acSaveNo
            ' place form to open navigation form here
        Else
            Reset_Fields
            vLoginAttempts = vLoginAttempts + 1
            If vLoginAttempts = intMaxLogonAttempts Then
                DoCmd.Close
                 MsgBox "all " & intMaxLogonAttempts & " attempts used. Database will now close", vbOKOnly, "Notice..."
            Else
                Me.lbl_Login_Count.Visible = True
                Me.lbl_Login_Count.Caption = "You have used " & vLoginAttempts & " out of " & intMaxLogonAttempts & " login attempts. After all " & intMaxLogonAttempts & "have been used, you will be required to have your passwrod reset by an authorised user."
                updateField "tbl_Contacts", "LogonAttempts", "UserName", vDBUserName, vLoginAttempts
    
            End If
        End If
        
    End Sub
    Private Sub cmd_Cancel_Click()
    On Error GoTo Err_cmd_Cancel_Click
    
        DoCmd.Close
    
    Exit_cmd_Cancel_Click:
        Exit Sub
    
    Err_cmd_Cancel_Click:
        MsgBox Err.Description
        Resume Exit_cmd_Cancel_Click
        
    End Sub
    
    Private Sub lbl_Login_Error_Click()
            MsgBox "Coming soon. Password management !!  ", vbOKOnly, "Notice..!"
        
    End Sub
    Private Sub txt_Password_AfterUpdate()
    cmd_Login_Click
    End Sub
    
    Private Function Reset_Fields()
            Me.lbl_Login_Error.Visible = True
            Me.lbl_Click_Here.Visible = True
            Me.txt_UserName = ""
            Me.txt_Password = ""
            Me.txt_UserName.SetFocus
    End Function

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

Similar Threads

  1. Runtime Error 3021
    By paddon in forum Programming
    Replies: 12
    Last Post: 03-14-2011, 12:14 PM
  2. Replies: 0
    Last Post: 02-22-2011, 04:18 PM
  3. Error in Runtime Only
    By drunkinmunki in forum Programming
    Replies: 7
    Last Post: 12-16-2010, 03:43 PM
  4. runtime error 2448
    By ds_8805 in forum Forms
    Replies: 3
    Last Post: 04-14-2010, 07:32 PM
  5. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 PM

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