Combo box multivalues are lost outside of change event

Kronix

Registered User.
Local time
Today, 11:30
Joined
Nov 2, 2017
Messages
102
This is a weird problem. My combo box only has values inside of it's onChange event in VBA. Its ItemsSelected.Count value is 0 in every other function, but correct in the onChange event. Trying to access a value via ItemsSelected(0) produces an error in every function except for the onChange event. I can see on the form that values are selected in the combo box the whole time.
 
from your heading and description I presume this is based on a multi value field?

ItemsSelected relates to a multiselect listbox which is a different animal. In a normal combo, ItemsSelected will either be 0 or 1 because you can only select one item.
 
No, I am using a combo box with multiselect based on a multivalued table field. The combo box that drops down allows me to place check marks next to multiple values. As I said, the OnChange sub allows me to retrieve the values via ItemsSelected(x) and Count properties as in a listbox, but only in the OnChange sub.
 
No, I am using a combo box with multiselect based on a multivalued table field.
that is what I said.

multivalue fields have lots of limitations - this is one of them
 
The reason for this is the Combo is actually a recordset.
You can't really access it if you are on New record.
After saving the record you go back to the record to enumerate what you have ticked:
Code:
    Dim rs As DAO.Recordset2
    Dim str As String
    
    Set rs = Me.Recordset("yourComboName").Value
    With rs
        If Not (.BOF And .EOF) Then .MoveFirst
        While Not .EOF
            str = str & "," & .Fields("Value")
            .MoveNext
        Wend
        .Close
    End With
    Set rs = Nothing
    If str <> "" Then MsgBox str
 
CJ London I thought you were making a differentiation between combo boxes and listboxes. I don't understand what limitation you are referring to, or whether you answered my question.

arnelgp that just returns the list of possible options. I am talking about retrieving the currently selected options. This is supposed to be done using "combobox.itemsselected(x)" or "combobox.column(2, combobox.itemsselected(x))" for lookup fields along with "For x = 0 to combobox.itemsselected.count" but all that only works in the onChange event.
 
I thought you were making a differentiation between combo boxes and listboxes
my point is you are trying to use the property behaviour of a multiselect listbox to a multivalue combobox.

I don't understand what limitation you are referring to
multivalue fields have limited functionality - as you are discovering. Not sure how else to say it. Arnelgp has provided a solution for you which does not use the properties you are trying to use. Go with that
 
I am using what you call a multiselect combo box. The multiselect combo box allows me to select multiple items simultaneously, which are stored in a multivalue field in a table. Yes, multiple items, each separated by a semicolon, saved in the same field, based on a list of possible values contained in a Lookup Table each with a text value and a corresponding numerical key value that is actually saved. That means multiple key values saved in the same field, appearing to be separated by a semicolon, but only editable through the check marks in the combo box, either through the combo box I am using on the form, or the combo box that is built into tables specifically for multivalue fields, both combo boxes containing check boxes for each value to allow multiselect. Microsoft calls such fields multivalue fields, so I used that word, but since you think that does not mean multiselect, let me be clear that it is possible to select multiple items in the combo box and store these multiple values in what Microsoft calls a multivalue field. If you look at my other thread I was also wondering how to determine whether the multiple items selected in one multivalue field are a subset of another.

It appears both of you did not understand the question, so maybe now somebody can give a proper answer.
 
I am using what you call a multiselect combo box.
there is no such thing as a multiselect combo box. You have a multiselect listbox or a multivalue combobox

Yes, multiple items, each separated by a semicolon, saved in the same field
no - that is just how it is presented

read this guide so you understand what you actually have

https://support.office.com/en-us/ar...d-fields-7c2fd644-3771-48e4-b6dc-6de9bebbec31
in particular this bit

The answer is that the database engine in Office Access 2007 doesn't actually store the values in a single field. Even though what you see and work with appears to be a single field, the values are actually stored independently and managed in hidden, system tables.
 

Users who are viewing this thread

Back
Top Bottom