Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-select listbox issues

Status
Not open for further replies.

kj27

Programmer
Mar 16, 2010
30
0
0
US
Greetings,

I have an issue which I'm hoping to get some help with. There is a DynaSet form which is tied to a table called: tblBasicInfo.

Everything works as expected except for a listbox. I have placed a checkbox next to it, to allow users to select all the entries:



Code:
Private Sub chkAllSpecialties_Click()

Dim i As Integer

Dim selection As Boolean
selection = chkAllSpecialties.Value

For i = 0 To lstSpecialties.ListCount - 1
lstSpecialties.SetFocus
lstSpecialties.Selected(i) = selection
Next i

End Sub

This works as expected. But I can't seem to get the selected values stored in the Control Source field (which is a Long Text field).

The values don't get stored even if I manually select values. The values for all other fields (including the checkbox) get stored and populate upon form load as expected.

Any insight with this issue is greatly appreciated.
 
Not sure what you are expecting to happen. A standard multiselect listbox cannot be bound to a field; a single field cannot store multiple values. Are you expecting the values to be concatenated somehow? If you want to store multiple values in a single field you would need to use a multivalue field and a multivalue field control, not a standard listbox. If you want to concatenate the values somehow you would have to write code, and I would not recommend it.
 
Thanks for the reply. I updated the field to be multi-select and the control to be a listbox. So multiple selections can now be stored. The desired behavior is that the user should be able to check/un-check the 'Select All' checkbox and all/none of the listbox values should get either selected or unselected and the result should get stored. The selection/un-selection is easily accomplished via:

Code:
Private Sub chkAllSpecialties_Click()
    Dim i As Integer
    
    Dim selection As Boolean
    selection = chkAllSpecialties.Value
        
        For i = 0 To SpecialtiesSelected.ListCount - 1
            SpecialtiesSelected.Selected(i) = selection
        Next i
End Sub

The problem is that the selection/un-selection does not result in an update to the underlying multi-value field.
 
A multi select field has its own set of controls and you cannot use a standard listbox as previously stated.
 
Personally I don't like to 'juggle' information between variables.

Code:
Private Sub chkAllSpecialties_Click()
    Dim i As Integer
    
    With [blue]lst[/blue]SpecialtiesSelected
        For i = 0 To .ListCount - 1
            .Selected(i) = chkAllSpecialties.Value
        Next I
    End With
End Sub

But that may be just me... :)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Hi MajP,

Good point - and a correction on my part. I meant that I changed the field type to be a multivalue and not a multi-select. I believe multivalue fields can be represented visually as ListBoxes or ComboBoxes. I decided to represent it as a ListBox. Now if I manually check multiple values, the selections are stored in the multivalue field correctly.

I am also able to use the check all checkbox to select all the values appearing in the listbox. Unfortunately when moving to the next record, these automatically selected values do not get stored into the multivalue field.

So I believe the type of field, the type of control and the association are correct. But something is missing that would allow the associated field to be updates with the values of the automatically selected values in the list box.

Thanks.
 
I cannot see the problem, but I tested it and it worked. I created a multivalue field, and selected/deselected all values and the selected values were stored. There may be something else going on.
 
Thanks for the update. Just out of curiosity, did you select/de-select all using an event (something similar to what was posted on check/uncheck) or did you select/de-select manually. When I do it manually, the field is indeed updated. When I click the independent check-box to select/de-select all, the listbox entries all get get selected/de-lected as expected, but the field never gets updated.
 
I did it in code like you did, and it seemed to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top