List Box Selection

N

NEWER USER

I am having trouble underrstanding why this code is flawed The first row in
my List Box "Acura" is NOT getting selected... All other rows are selected
and highlighted...WHY? SelectMake is a Check Box; any help appreciated

Private Sub SelectMake_AfterUpdate()
Dim varItem As Variant
Dim strWhere As String
Dim varSelected As Variant
'Select corresponding rows in lstMake List Box; Update lstModel
If Me.SelectMake = -1 And Me.lstType.Column(1) = "Asian" Then
SetSelections Me.lstMake, 0, "Acura", "Asuna", "Daihatsu", "Daewoo",
"Geo", "Honda", "Hyundai", _
"Infiniti", "Isuzu", "Kia", "Lexus", "Mazda", "Mitsubishi",
"Nissan", "Subaru", "Suzuki", "Toyota", _
"Sterling", "Scion"
End If

If Me.SelectMake = 0 Then
For Each varItem In lstMake.ItemsSelected
lstMake.Selected(varItem) = False
Next varItem
End If

If Me!lstMake.ItemsSelected.Count > 0 Then
strWhere = "WHERE [Make] IN ("
For Each varSelected In Me!lstMake.ItemsSelected
strWhere = strWhere & "'" & Me!lstMake.ItemData(varSelected) & "', "
Next varSelected
strWhere = Left(strWhere, Len(strWhere) - 2) & ") "

Me.Controls("lstModel").RowSource = "SELECT DISTINCT " & _
"[Model] FROM [qryModels] " & strWhere & _
"ORDER BY [Model]"
Else
Me!lstModel.RowSource = ""
End If

End Sub
 
P

Pendragon

I just ran into something similar where I was trying to create a Select All
command button. I had initially tried X = 1 to .ListCount but that only
highlighted all except for the first item. Trial and error resulted in the
following successful code.

Dim varSelected As Variant

With Me.lstGroup
For X = 0 To .ListCount - 1
.Selected(X) = True
Next X
End With

Hope that helps with what you need.

Ross
 
N

NEWER USER

Your code works well foir selecting the entire list. I am trying to isolate
only "Asian" vehicles from my list of 100+ rows. That's why I named each
vehicle make I wanted. i will keep trying and thanks for the help.

Pendragon said:
I just ran into something similar where I was trying to create a Select All
command button. I had initially tried X = 1 to .ListCount but that only
highlighted all except for the first item. Trial and error resulted in the
following successful code.

Dim varSelected As Variant

With Me.lstGroup
For X = 0 To .ListCount - 1
.Selected(X) = True
Next X
End With

Hope that helps with what you need.

Ross

NEWER USER said:
I am having trouble underrstanding why this code is flawed The first row in
my List Box "Acura" is NOT getting selected... All other rows are selected
and highlighted...WHY? SelectMake is a Check Box; any help appreciated

Private Sub SelectMake_AfterUpdate()
Dim varItem As Variant
Dim strWhere As String
Dim varSelected As Variant
'Select corresponding rows in lstMake List Box; Update lstModel
If Me.SelectMake = -1 And Me.lstType.Column(1) = "Asian" Then
SetSelections Me.lstMake, 0, "Acura", "Asuna", "Daihatsu", "Daewoo",
"Geo", "Honda", "Hyundai", _
"Infiniti", "Isuzu", "Kia", "Lexus", "Mazda", "Mitsubishi",
"Nissan", "Subaru", "Suzuki", "Toyota", _
"Sterling", "Scion"
End If

If Me.SelectMake = 0 Then
For Each varItem In lstMake.ItemsSelected
lstMake.Selected(varItem) = False
Next varItem
End If

If Me!lstMake.ItemsSelected.Count > 0 Then
strWhere = "WHERE [Make] IN ("
For Each varSelected In Me!lstMake.ItemsSelected
strWhere = strWhere & "'" & Me!lstMake.ItemData(varSelected) & "', "
Next varSelected
strWhere = Left(strWhere, Len(strWhere) - 2) & ") "

Me.Controls("lstModel").RowSource = "SELECT DISTINCT " & _
"[Model] FROM [qryModels] " & strWhere & _
"ORDER BY [Model]"
Else
Me!lstModel.RowSource = ""
End If

End Sub
 
N

NEWER USER

Just wanted to say THANKS AGAIN.

I created a query and on the After Update Event of the first list box, I
displayed the records I wanted and then used your code to select all the
records from the second list box. Happy Holidays.

Pendragon said:
I just ran into something similar where I was trying to create a Select All
command button. I had initially tried X = 1 to .ListCount but that only
highlighted all except for the first item. Trial and error resulted in the
following successful code.

Dim varSelected As Variant

With Me.lstGroup
For X = 0 To .ListCount - 1
.Selected(X) = True
Next X
End With

Hope that helps with what you need.

Ross

NEWER USER said:
I am having trouble underrstanding why this code is flawed The first row in
my List Box "Acura" is NOT getting selected... All other rows are selected
and highlighted...WHY? SelectMake is a Check Box; any help appreciated

Private Sub SelectMake_AfterUpdate()
Dim varItem As Variant
Dim strWhere As String
Dim varSelected As Variant
'Select corresponding rows in lstMake List Box; Update lstModel
If Me.SelectMake = -1 And Me.lstType.Column(1) = "Asian" Then
SetSelections Me.lstMake, 0, "Acura", "Asuna", "Daihatsu", "Daewoo",
"Geo", "Honda", "Hyundai", _
"Infiniti", "Isuzu", "Kia", "Lexus", "Mazda", "Mitsubishi",
"Nissan", "Subaru", "Suzuki", "Toyota", _
"Sterling", "Scion"
End If

If Me.SelectMake = 0 Then
For Each varItem In lstMake.ItemsSelected
lstMake.Selected(varItem) = False
Next varItem
End If

If Me!lstMake.ItemsSelected.Count > 0 Then
strWhere = "WHERE [Make] IN ("
For Each varSelected In Me!lstMake.ItemsSelected
strWhere = strWhere & "'" & Me!lstMake.ItemData(varSelected) & "', "
Next varSelected
strWhere = Left(strWhere, Len(strWhere) - 2) & ") "

Me.Controls("lstModel").RowSource = "SELECT DISTINCT " & _
"[Model] FROM [qryModels] " & strWhere & _
"ORDER BY [Model]"
Else
Me!lstModel.RowSource = ""
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top