Update ListBox from CheckBox

LB79

Registered User.
Local time
Today, 08:50
Joined
Oct 26, 2007
Messages
505
Hello,

I wonder if anyone can tell me how i can populate a listbox with checkbox data.
EG I have 5 checkboxes (1 to 5). When I click on checkbox 1 and 3, the listbox requeries and shows 1 and 3.

Thanks for any advice
 
These are unbound checkboxes on a form and you want to check some of them
and then show those values in a listbox? Is that correct?
 
Thats correct yes.
 
Ive come accross this very old post on here which seems to be exactly what I want, however, it doesnt really explain how its done. Does anyone know how this was achieved?

Thanks

Update list box based on state of check box
This is similar to a question posted by Kevin S in October but I'm using Check Boxes rather than a combo box

BACKGROUND: The Form has two sections. One side consists of 7 check boxes and the other side is a listbox. Each time a check box is checked, a requery occurs, updating the records that match the checks. The other side of the form is a list box that is based on the query created with the check boxes.

GOAL: Update the list box everytime a box is checked, without prompting the user to click a command button

WHAT'S REALLY HAPPENING: The list box never changes. It always shows the entire list. To ensure that the query is updating, after every event, I have an additonal dialog box open with the same list box, and it updates as expected. However, the added dialog box does not update on the fly, I have to close it and reopen it for the list to be updated

QUESTION: How do I update the list box without prompting the user or opening a new form? I've tried me.listbox.requery just about everywhere. Is there another command to refresh?

Thanks.
 
Hello,

I've been working on something that should be far more simple, but im a little stuck

I have a checkbox which when checked relevant data appears in the list, but when unchecked I receive an error. “Run time error 6013. Unable to removed item. “|” not found in list2”. I'm not sure what this means as I have no | in my data.
This is my code. Can anyone advise?

Thanks
Private Sub CH1_AfterUpdate()
If Me.CH1 = -1 Then
Dim CHK1 As String
CHK1 = "AA;BBB;CCCC"
List.AddItem Item:=CHK1
Else
Exit Sub
List.RemoveItem CHK1
End If
End Sub
 
This is what Access states

RemoveItem Method
See AlsoApplies ToExampleSpecificsRemoves an item from the list of values displayed by the specified list box control or combo box control.

expression.RemoveItem(Index)
expression Required. An expression that returns one of the objects in the Applies To list.

Index Required Variant. The item to be removed from the list, expressed as either an item number or the list item text.

Remarks
This method is only valid for list box or combo box controls on forms. Also, the RowSourceType property of the control must be set to "Value List".

List item numbers start from zero. If the value of the Index argument doesn't correspond to an existing item number or the text of an existing item, an error occurs.

Use the AddItem method to add items to the list of values.

Example
This example removes the specified item from the list in a list box control. For the function to work, you must pass it a ListBox object representing a list box control on a form and a Variant value representing the item to be removed.

Function RemoveListItem(ctrlListBox As ListBox, _
ByVal varItem As Variant) As Boolean

' Trap for errors.
On Error GoTo ERROR_HANDLER

' Remove the list box item and set the return value
' to True, indicating success.
ctrlListBox.RemoveItem Index:=varItem
RemoveListItem = True

' Reset the error trap and exit the function.
On Error GoTo 0
Exit Function

' Return False if an error occurs.
ERROR_HANDLER:
RemoveListItem = False

End Function
 
Thansk for the details, but even using the sample code in that
Remove the list box item and set the return value
' to True, indicating success.
ctrlListBox.RemoveItem Index:=varItem
RemoveListItem = True
I still get the “Run time error 6013. Unable to removed item. “|” not found in list” message. Do you know where the | could be coming from?

Thanks
 
RemoveItem is expecting a index value not a string. you code is actually saying

RemoveItem AA;BBB;CCCC

Not

RemoveItem 0
 
I see. Is there any way to remove a specified item rather then an index item as they may not always be in the same order?
 
Dim nIndex as integer

For nIndex = 0 To Me.ListBox.ListCount -1
If Me.Listbox(nIndex) = str then
RemoveItem(nIndex)
Exit for
End If
Next

This is aircode and untested.
 

Users who are viewing this thread

Back
Top Bottom