Trouble with Multi List Box

N

NEWER USER

I am having trouble getting the entry in the field to Select itself.
SelectMake is a check box
lstType is a Multi List Box

When I select "Asian" in the List Box and check the Check Box, all the Asian
vehicles are selected except "Acura". It is displayed, but I must manually
hold down the Ctrl key and select. I played with the sorting from ascending
to descending and it worked, but then "Yugo" in Eurpoean (which is now first
in the list) will not select. Any help on why the first record will not
select is 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) = "European" Then
SetSelections Me.lstMake, 0, "Alfa Romeo", "Audi", "Austin",
"Bentley", "Bertone", "BMW", "Ferrari", _
"Fiat", "Jaguar", "Land Rover", "Lotus", "Maserati", "Maybach",
"Mercedes Benz", "MG", "Merkur", "Mini", "Opel", "Peugeot", _
"Porsche", "Renault", "Rolls Royce", "Rover", "Saab", "Smart",
"Triumph", "Volvo", "Volkswagen", "Yugo"
End If

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 = -1 And Me.lstType.Column(1) = "Domestic" Then
SetSelections Me.lstMake, 0, "AM General", "American Motors",
"Buick", "Cadillac", "Checker", _
"Chevrolet", "Chrysler", "DeLorean", "Dodge", "Eagle", "Ford",
"Freightliner", "GMC", "Hummer", _
"International", "Jeep", "Lincoln", "Mercury", "Oldsmobile",
"Plymouth", "Pontiac", "Saturn", _
"Shelby"
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

Nicholas Scarpinato

Well, without knowing exactly how this is working, I'm shooting in the dark a
bit... but if you're selecting the type car (euro, domestic, etc.) from
lstType and then updating lstMake, then this is somewhat easier. Set up a
second column in lstMake, which you won't have to see (set the column size to
0), and use that column to store the "type" of car it is. Then you can use
that to select the correct makes for that type, using a listbox selection
routine like this:

Dim i as Integer
For i = 0 to Me.lstMake.ListCount - 1
If Me.lstMake.Column(1,i) = Me.lstType Then
Me.lstMake.Selected(i)=True
Else
Me.lstMake.Selected(i)=False
End If
Next i

Also, keep in mind that the correct starting index for the rows and columns
of a ListBox is zero, not 1. If you select index 1, you're selecting the
second row in the listbox.



NEWER USER said:
I am having trouble getting the entry in the field to Select itself.
SelectMake is a check box
lstType is a Multi List Box

When I select "Asian" in the List Box and check the Check Box, all the Asian
vehicles are selected except "Acura". It is displayed, but I must manually
hold down the Ctrl key and select. I played with the sorting from ascending
to descending and it worked, but then "Yugo" in Eurpoean (which is now first
in the list) will not select. Any help on why the first record will not
select is 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) = "European" Then
SetSelections Me.lstMake, 0, "Alfa Romeo", "Audi", "Austin",
"Bentley", "Bertone", "BMW", "Ferrari", _
"Fiat", "Jaguar", "Land Rover", "Lotus", "Maserati", "Maybach",
"Mercedes Benz", "MG", "Merkur", "Mini", "Opel", "Peugeot", _
"Porsche", "Renault", "Rolls Royce", "Rover", "Saab", "Smart",
"Triumph", "Volvo", "Volkswagen", "Yugo"
End If

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 = -1 And Me.lstType.Column(1) = "Domestic" Then
SetSelections Me.lstMake, 0, "AM General", "American Motors",
"Buick", "Cadillac", "Checker", _
"Chevrolet", "Chrysler", "DeLorean", "Dodge", "Eagle", "Ford",
"Freightliner", "GMC", "Hummer", _
"International", "Jeep", "Lincoln", "Mercury", "Oldsmobile",
"Plymouth", "Pontiac", "Saturn", _
"Shelby"
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