Multiple selection from combobox to multiple rows (1 Viewer)

ZKHADI

Member
Local time
Today, 13:26
Joined
Apr 5, 2021
Messages
118
hy buddies
i have a combobox multiple checkbox selection
i want as i select multiple record it update in multiple rows is it possible?

see image...
 

Attachments

  • Untitled.png
    Untitled.png
    80.4 KB · Views: 69

June7

AWF VIP
Local time
Today, 00:26
Joined
Mar 9, 2014
Messages
5,475
A combobox with checkboxes can only be created when it is bound to a field set to be multi-value. A multi-value field is actually a special field type used by Access. AFAIK, no other db platform uses this. What a multi-value field actually does is hold pointers/links to a hidden table where each item shown in the MVF is really a separate record. A query can pull these records to display in individual rows. Either don't use MVF or learn how to handle them.
 

ebs17

Well-known member
Local time
Today, 10:26
Joined
Feb 7, 2020
Messages
1,949
update in multiple rows
To do this, you need a query that has implemented your selection in a valid filter (WHERE expression). That's the easy and the difficult.

Code:
SELECT * FROM TableX WHERE FieldA IN (2, 4, 7)    ' ("Tom", "Anna", "Paul") for Strings
SELECT * FROM TableX WHERE FieldA = 2 OR FieldA = 4 OR FieldA = 7
These are two variants of a selection query with a valid filter.

Now look at what your ComboBox gives you as a return value, the return value can be something other than what you see on the surface.
Code:
Debug.Print Me.cboTestName.Value
Now all you have to do is convert the current return into a filter.

I myself am on the side of @June7 and avoid such newer features as this ComboBox because I prefer to use my own and open relationships instead of hidden relationships and thus understand more easily what I can and must do. The understanding of simple things allows me better to turn to more complex things.
 

ZKHADI

Member
Local time
Today, 13:26
Joined
Apr 5, 2021
Messages
118
i
To do this, you need a query that has implemented your selection in a valid filter (WHERE expression). That's the easy and the difficult.

Code:
SELECT * FROM TableX WHERE FieldA IN (2, 4, 7)    ' ("Tom", "Anna", "Paul") for Strings
SELECT * FROM TableX WHERE FieldA = 2 OR FieldA = 4 OR FieldA = 7
These are two variants of a selection query with a valid filter.

Now look at what your ComboBox gives you as a return value, the return value can be something other than what you see on the surface.
Code:
Debug.Print Me.cboTestName.Value
Now all you have to do is convert the current return into a filter.

I myself am on the side of @June7 and avoid such newer features as this ComboBox because I prefer to use my own and open relationships instead of hidden relationships and thus understand more easily what I can and must do. The understanding of simple things allows me better to turn to more complex things.
i will try
 

moke123

AWF VIP
Local time
Today, 04:26
Joined
Jan 11, 2013
Messages
3,921
I use a public function with multiselect list boxes to construct an in clause.

Code:
Public Function getLBX(lbx As ListBox, Optional intColumn As Variant = 0, Optional Seperator As String = ",", _
                       Optional delim As Variant = Null) As String

'Iterates thru the multiselect listbox and constructs an array of the selected items
'Arguments:
'Lbx is Listbox Object ie.Me.MyListbox
'intColumn is the column # to be returned
'Seperator is the character seperating items in array returned
'Delim is optional delimiter to be return in array ie. #1/1/2001#,#12/25/2015#

    Dim strlist As String
    Dim varSelected As Variant

    'On Error GoTo getLBX_Error

    If lbx.ItemsSelected.Count = 0 Then
        'MsgBox "Nothing selected"
    Else

        For Each varSelected In lbx.ItemsSelected

            If Nz(lbx.Column(intColumn, (varSelected)), "") <> "" Then

                strlist = strlist & delim & lbx.Column(intColumn, (varSelected)) & delim & Seperator

            Else

                strlist = strlist

            End If

        Next varSelected

        If Nz(strlist, "") <> "" Then

            strlist = Left$(strlist, Len(strlist) - 1)  'remove trailing comma

        End If
    End If

    getLBX = strlist

    On Error GoTo 0
    Exit Function

getLBX_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure getLBX of Module modLBX"

End Function

You would impliment like

Code:
"SELECT * FROM TableX WHERE FieldA IN ("  & getLBX(Me.YourListBoxName) & ")"

There are arguments in the function to change which column gets returned and what delimiters they may need.
 

ZKHADI

Member
Local time
Today, 13:26
Joined
Apr 5, 2021
Messages
118
i didnt understant what to do. kindly find attachment and do the same in file
 

Attachments

  • Lab system.accdb
    2.8 MB · Views: 69

Users who are viewing this thread

Top Bottom