MS Access 2007 - 循环浏览列表框中的值以获取 SQL 语句的 ID

发布于 2024-09-11 03:56:46 字数 351 浏览 9 评论 0原文

假设我有两个表,一个用于事务,另一个表的主键是第一个表中的外键,这种关系只是将位置与事务相关联。

我有一个带有列表框的表单,显示所有潜在位置,以便用户可以打开一些仅与给定位置相关的仪表板表单。所以我知道如何将数据从选择传递到仪表板,但是我现在希望用户能够从第一个列表中选择多个位置。

因此,如果我使用 SQL 语句,WHERE 子句就像这样

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

,但是我如何将这种类型的方法等同于选择多个选项呢?我确信有某种类型的循环我没有注意到。

谢谢 贾斯汀

Lets say I have two tables, one for transactions, and another table who's primary key is the foreign key in the first table, and this relationship simply associates locations to transactions.

I have a form with a list box that shows all the potential locations, so that the user can open some dashboard forms that only pertain to a given location. So I know how to pass the data from the selection to the dashboard, however I would now like the user to have the capability to select multiple locations from the first list.

so if I use a SQL statement the WHERE clause is like

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

but how would I equate this type of method to selecting multiple choices? I am sure there is some type of loop that escapes me.

Thanks
Justin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下慵懒的猫 2024-09-18 03:56:46

您可以使用

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

可以像这样获取列表:

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

listofvalues = Mid(listofvalues,2)

这是数字列表,字符串列表需要引号。

You can use

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

The list can be obtained like so:

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

listofvalues = Mid(listofvalues,2)

This is for a numeric list, a list of strings needs quotes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文