Hello: I have a ListBox control - where Multi Select property is set to Extended - on a subform. The values are being loaded into the control in alpha order as expected from the Row Source = Table/Query.
The problem is that when the list is loaded the position or focus moves to the end of the list (Zapata County) instead of the beginning of the list (Anderson). I have checked all settings for the control, subform, and main form but I am unable to determine why the list does not load at the beginning.
I have enclosed the code I'm using for the ListBox control below. Let me know if I need to provide anything more to clarify my issue. Thank you!
BEGIN CODE BLOCK
Private Sub Form_Current()
Dim oItem As Variant
Dim bFound As Boolean
Dim sTemp As String
Dim sValue As String
Dim sChar As String
Dim iCount As Integer
Dim iListItemsCount As Integer
sTemp = Nz(Me!txt_CountiesInServiceAreaSelections.Value, " ")
iListItemsCount = 0
bFound = False
iCount = 0
Call clearListBox
For iCount = 1 To Len(sTemp) + 1
sChar = Mid(sTemp, iCount, 1)
If StrComp(sChar, ",") = 0 Or iCount = Len(sTemp) + 1 Then
bFound = False
Do
If StrComp(Trim(Me!lst_CountiesInServiceArea.ItemData (iListItemsCount)), Trim(sValue)) = 0 Then
Me!lst_CountiesInServiceArea.Selected(iListItemsCo unt) = True
bFound = True
End If
iListItemsCount = iListItemsCount + 1
Loop Until bFound = True Or iListItemsCount = Me!lst_CountiesInServiceArea.ListCount
sValue = ""
Else
sValue = sValue & sChar
End If
Next iCount
End Sub
Private Sub clearListBox()
Dim iCount As Integer
For iCount = 0 To Me!lst_CountiesInServiceArea.ListCount
Me!lst_CountiesInServiceArea.Selected(iCount) = False
Next iCount
End Sub
Private Sub cmd_ClearListBoxCounties_Click()
On Error GoTo cmd_ClearListBoxCounties_Click_Err
On Error Resume Next
Call clearListBox
Me!txt_CountiesInServiceAreaSelections.Value = Null
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
cmd_ClearListBoxCounties_Click_Exit:
Exit Sub
cmd_ClearListBoxCounties_Click_Err:
MsgBox Error$
Resume cmd_ClearListBoxCounties_Click_Exit
End Sub
Private Sub cmd_ListBoxSelections_Click()
Call SQL_Criteria_Str
End Sub
Function SQL_Criteria_Str() As String
'Build Where Condition for SQL Statement (Other Columns - String data type)
Dim varItem As Variant
Dim ctl As Control
Dim strCriteria As String
Set ctl = Me.lst_CountiesInServiceArea
strCriteria = ""
For Each varItem In ctl.ItemsSelected
'Use the ItemData Property to select the Bound Column
'Use the Column Property to specify the Row, Column
strCriteria = strCriteria + ctl.Column(1, varItem) & ": " & vbCrLf
Next varItem
Me.txt_CountiesInServiceAreaSelections = strCriteria
End Function
END CODE BLOCK