List Box multiple value selection - ms-access

I have created form based on query output. I had used three comboboxes and one list box. First combobox gives me list of Dept, selection of Dept on second gives me location of that Dept (distinct), the third gives me (distinct) project from that location, then next is list box who displays the some codes of that project. The problem is I am able to select only one code from that list and get output in Excel.
If I wanted to select two values at a time, how would I do that?
If I select Multi Select from list box property than I am able to select multiple values but I am not getting output.

When a List Box has its Multi Select property set to "None" then you can retrieve the selected value by simply referring to
Me.List0.Value
However, for multi-select List Box controls you need to iterate through the ItemsSelected collection to determine the items that are selected:
Dim ItemIndex As Variant
For Each ItemIndex In Me.List0.ItemsSelected
MsgBox Me.List0.ItemData(ItemIndex)
Next

Related

Pass parameters from one combo box to another using two forms in Microsoft Access

Just started working with Access 2016 for a project I am on.
How can I pass selected data from one form in access to another?
That Selection will be the determining factor on what data is presented in drop down menus. Basically, if I select a department, I want that departments data to be the "select from" data on the next.
I'm not really sure if this is a clear question, so I've added pictures.
The Goal is to not have to create a new form for every department.
Update:
So I am able to link the department combo box with the lineid box with the following Query
SELECT DISTINCT Line.lineName, Department.departmentName
FROM Line INNER JOIN Department ON Line.departmentID = Department.departmentID
WHERE (((Department.departmentName)=[Forms]![Production_Select_Data_Input_Destination].[OpenArgs]));
I need to get the parameter passed so this is not prompt and the combo box for lineId loads a select list of lineId's that are within the selected department.
I figured it out using
Private Sub btnEnterDataInput_Click()
DoCmd.OpenForm "frmDataInput", , , , , , OpenArgs:=cboDepartmentName
End Sub
In my first form,
and
[Forms]![frmSelectDataInput]![cboDepartmentName]
in my second form combobox row source query.
in my second form.

How do I tie a selected item in a list box to a query (MS Access)?

I have a couple of list boxes on a form that I've created. One of the listboxes has a bunch of supplier names (lst_SupplierName). Upon selecting a supplier name it then auto-populates all Part Numbers under that supplier in another list box (lst_PartNumber).
I would like to take it a step further. So The Part Number listbox is now populating I would like to select a part number and based on that part number be able to create a query that lists all required attributes associated with that part number from the table it's contained in.
Make 2 lists, first one that queries supplier table, second one that queries part table that will use value of first list to query parts only for that supplier. Here is sample tables I created:
And form:
The first list row source is:
SELECT [tblSuplier].[SupID], [tblSuplier].[SupName] FROM tblSuplier ORDER BY [SupName];
Second list row source is:
SELECT tblPart.PartID, tblPart.SupID, tblPart.PartName, tblPart.PartDescr FROM tblPart WHERE (((tblPart.SupID)=[Forms]![frmMain]![lstSup]));
To make second list update, when you select something in first list, you need to add 'after update' event on first list:
Private Sub lstSup_AfterUpdate()
lstPart.Requery
End Sub
Now, you can use after update event to populate different fields on form from parts list the same way - by simply placing value into fields, like txtDescription = lstPart.column(2=3) .
If you have any questions, please let me know.

Synchronize two multi select combo boxes on a form in MS Access 2007

I am working with two multi select combo boxes on an Access 2007 form. The first multi select combo box is a list of Diagnoses called cboPatDX. After the user selects any number of Diagnoses, I want to fill the next field called DXUnclear with just the selections made on cboPatDX. Most of the answers I have found online do not apply to the multi select combo box. Among many options I have tried, this is the latest, but I get a type mismatch error:
Me.cboDXUnclear.RowSource = "SELECT ID, Diagnosis FROM tblOptsWorkingDX WHERE ID = Me.cboPatDX ORDER BY Diagnosis"
Me.cboDXUnclear = Me.cboPatDX.ItemData(0)
I would appreciate any help with this, including other methods to make this work.
Here's two links that might help you:
filter a query based on multiple list boxes in a form
https://bytes.com/topic/access/answers/446193-filtering-query-values-multi-select-list-box

MS-Access 2013; Change combobox options based on record data in multi-record form

I have a form with multiple records, one per row, being pulled from a table. I have 2 ComboBox controls on each row. The first ComboBox's options are linked to a table of Categories. The second ComboBox's options need to be linked to the subcategories of the first ComboBox.
I have tried having the WHERE statement in the row source at design time, which produced all the subcategories.
I have tried having the WHERE statement, and a requery command, on the change event of the category ComboBox, which produced the subcategories for the last changed category. This was an issues because all the rows would have the same options, instead of the options being based on the category for that record/row.
What I need is for each row to query the subcategory/category mapping table and filter the results based on that row's category selection. Is this possible? If so, how can this be done? I am not afraid of using VBA to get the results I need.
In the On_Current event of the form, you can change the row source of the second combo box dynamically dependant on the value of the column of the first combo box. You probably also need to do it on the after_update event of the first combo box to.
Something like this
Select Case Me.cboCategory
Case "Category 1"
Me.cboSubCategory.RowSource = "qryCat1Subclass"
Case "Category 2"
Me.cboSubCategory.RowSource = "qryCat2Subclass"
Case Else
Me.cboSubCategory.RowSource = ""
End Select
I don't have two combo boxes, just one, but its contents have to be based on a value in another field. This is how I do it.

Selecting Concatenated Item In ListBox (part of report)

I have a report with a listbox (which contains a concatenated field)
SELECT tbl_Employee.GID, tbl_Employee.Sname, tbl_Employee.Gname FROM tbl_Employee ORDER BY tbl_Employee.Sname, tbl_Employee.Gname;
I want to select one of the items of this listbox so that the value (GID) is taken over in textbox GID (which is used to fill tbl_Report)
But somehow I can't select Items in the ListBox in the report,
Anyone have a clue to why this is happening?
Overview of used Tables is added below:
This is not possible. Selectable Listboxes are not meant for reports, but you can use it in forms.