Results 1 to 5 of 5

Thread: Combo Box ListIndex Problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2018
    Location
    Texas
    Posts
    168

    Question Combo Box ListIndex Problem

    I get an "Invalid Procedure Call or Argrument " error when I try to set my combo box to show a default user, and then as the code tries to set the focus to a textbox (a password text) on the same form.
    After I close the error message, my form does have the correct User shown in in the ComboBox. Interestingly, the user name is highlighted.

    Doing Something Wrong -- Stumped.

    Code:
    Private Sub PopulateCboUserName()
    
            '<EhHeader>
            'On Error GoTo PopulateCboUserName_Err
            '</EhHeader>
    
        
    102     With cboUserName
        
    104         Do Until adoRecordset.EOF
    106             .AddItem adoRecordset![User Name]
    108             adoRecordset.MoveNext
                Loop
    
    
             'show the name of the default user in the cboUserName     
     
    112         .ListIndex = LF_GetListIndex(cboUserName, g_str_DefaultUser)
    
            End With
    
    
    114    Set adoRecordset = Nothing
    
            '<EhFooter>
            Exit Sub
    
    PopulateCboUserName_Err:
            MsgBox Err.Description & vbCrLf & _
                   "in xGELv2.frmStart.PopulateCboUserName " & _
                   "at line " & Erl
            Resume Next
            '</EhFooter>
    End Sub
    
    
    Private Sub cboUserName_Click()
    
    110     txtPassword = ""
    
    'I did some more drilling down and this is the statement that raises the error.
    ' This "cboUserName_Click" automatically happens after the PopulateCboUserName executes
            txtPassword.SetFocus 
    End Sub
    
    
    Function LF_GetListIndex(Combo As ComboBox, S$) As Integer
       Dim L9&
       
       For L9 = 0 To Combo.ListCount - 1
           If S$ = Combo.List(L9) Then
              LF_GetListIndex = L9
              Exit Function
           End If
       Next
       LF_GetListIndex = -1
       
    End Function
    Last edited by clickman; Jan 26th, 2021 at 08:49 AM.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Combo Box ListIndex Problem

    Is that code called from the form load event? Could be tryign to set focus to something that is not yet available for focus.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,149

    Re: Combo Box ListIndex Problem

    That's my suspicion as well...form_load. If desired, call these functions/subs from form_activate instead of form_load...that would solve the setFocus issue.
    Sam I am (as well as Confused at times).

  4. #4
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Combo Box ListIndex Problem

    Quote Originally Posted by SamOscarBrown View Post
    That's my suspicion as well...form_load. If desired, call these functions/subs from form_activate instead of form_load...that would solve the setFocus issue.
    Yup, what I do most of the time is have a form level flag.
    I most often use the Form_Activate instead of Form_Load
    One problem with that, is that Form_Activate can run more than once in the life of a Form.
    Thus the flag, I mentioned, gets set to tell me (the program) that Form_Activate has already run once, and the 'special' code knows to not run again

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2018
    Location
    Texas
    Posts
    168

    Re: Combo Box ListIndex Problem

    YES - That really helped me track it down.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width