-
Jan 26th, 2021, 08:45 AM
#1
Thread Starter
Addicted Member
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.
-
Jan 26th, 2021, 09:42 AM
#2
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.
-
Jan 26th, 2021, 01:36 PM
#3
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).
-
Jan 26th, 2021, 09:40 PM
#4
Re: Combo Box ListIndex Problem
Originally Posted by SamOscarBrown
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
-
Jan 29th, 2021, 07:36 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|