Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

multiselect list box keeps returning to none

Hi
i have a listbox which is being populated from an access table
it is populating fine
I want to make multiple selections by holding the control key down when selecting items so i change the property 'multi select' from 0 - none to 1 simple ( or 2 extended ) - i save the project , run the app and there is no multi select -- I return to design view and multi select is back to 0- none ? !!!
pulling my hair out !
any ideas ?
thanks
[473 byte] By [br3athe] at [2007-11-11 7:53:22]
# 1 Re: multiselect list box keeps returning to none
Please post the code you're using to populate the listbox.
Phil Weber at 2007-11-11 17:26:22 >
# 2 Re: multiselect list box keeps returning to none
hi phil
thanks for quick reply
the list box is being populated with an onloadevent of the form calls this
Private Sub Form_Load()

Call LoadListBox(Me.lstFields, "select fieldname from tblTempfield", "fieldname", True)
End Sub

Like i say the box is being populated fine - just refuses to multiselect ...
LoadListBox is in a module ....

Public Sub LoadListBox(ByRef oComboBox As ListBox, _
ByVal sSql As String, _
ByVal sField As String, _
Optional ByVal bClear As Boolean = True, _
Optional ByVal sItemDataField As String = "")

'Procedure: LoadComboBox
'Purpose : Load data into a ComboBox control.

'Arguments:
'oComboBox--The ComboBox control to load.
'sSQL--SQL SELECT statement that retrieves the required data.
'sField--The name of the field to add to the ComboBox control.
'bClear Optional--Clear the ComboBox before loading it.
'sItemDataField - Optional--The name of the field to store in ItemData.

'On Error GoTo errHandler

Dim rsRecords As ADODB.Recordset
Set rsRecords = New ADODB.Recordset
Dim g_CADOConnection As ADODB.Connection
Set g_CADOConnection = New ADODB.Connection

g_CADOConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & App.Path & "\a2a.mdb"


If bClear Then
oComboBox.Clear
End If

'Load recordset.
rsRecords.Open sSql, g_CADOConnection

'If g_CADOConnection.OpenRecordsetEx(rsRecords, sSql, True) Then
Do While Not rsRecords.EOF

'Add values to combo box.
oComboBox.AddItem rsRecords.Fields(sField).Value & ""

'Add itemdata value if one was specified.
If Len(sItemDataField) > 0 Then
oComboBox.ItemData(oComboBox.NewIndex) = _
rsRecords.Fields(sItemDataField).Value
End If

rsRecords.MoveNext
Loop
rsRecords.Close
Set rsRecords = Nothing

' End If
Exit Sub
br3athe at 2007-11-11 17:27:21 >
# 3 Re: multiselect list box keeps returning to none
Hmm. I thought perhaps the .Clear method reset .MultiSelect, but I just tested it with a simple program and .MultiSelect does not change. I would set a watchpoint on the lstFields.MultiSelect property so that the program breaks when its value changes.
Phil Weber at 2007-11-11 17:28:20 >
# 4 Re: multiselect list box keeps returning to none
hi phil - just to let you know - dont know what was wrong - added the items manually looping through a recordset instead of using a data source control - and multi select works now - (?) thanks again
br3athe at 2007-11-11 17:29:16 >