MS Access 2007 - moving through values ​​in a list box to capture an identifier for an SQL statement

Suppose I have two tables: one for transactions and another table whose primary key is the foreign key in the first table, and this relationship simply associates locations with transactions.

I have a list form that displays all potential locations so that the user can open some panel forms that only apply to a specific location. Therefore, I know how to transfer data from the selection to the control panel, but now I would like the user to be able to select several locations from the first list.

so if i use the SQL statement, the WHERE clause is like

.... WHERE LocationID = " & me.lstLocations.value & ";" 

but how to equate this type of method to the choice of several options? I am sure that there is some type of cycle that eludes me.

Thanks Justin

+2
source share
1 answer

you can use

 WHERE LocationID IN (" & listofvalues & ");" 

The list can be obtained as follows:

 For Each itm In Me.ListBox.ItemsSelected listofvalues = listofvalues & "," & Me.ListBox.Column(0, itm) Next listofvalues = Mid(listofvalues,2) 

This is for a numerical list, a list of strings requires quotation marks.

+6
source

Source: https://habr.com/ru/post/1383912/


All Articles