-1

I have created a form in Access which queries a single record in a set date range. This works beautifully. My question is how can I query multiple records from a form text box.

Something Similar to the SQL function

IN ('XXX','XXX','XXX')

I want my users to be able enter multiple values on the form and it will spit out the corresponding Data.

4

2 回答 2

0

当您希望允许多个条目时,通常最好有一个数据表子表单,用户可以在其中每行输入一个数据。然后,您可以像使用常规表一样在查询中使用子表单数据。

于 2013-09-28T18:27:25.993 回答
0

试试 Split() 函数。像这样的东西:

Dim arr() As String
Dim MySQL as String

If Len(Me!MyTextbox) > 1 Then
MySQL = "SELECT * FROM MyTable WHERE MyField in ("

arr = Split(Me!MyTextbox.Text, ",")
For i = LBound(arr) To UBound(arr)
    MySQL = MySQL & "'" & arr(i) & "', "
Next

MySQL = Left(MySQL, Len(MySQL) - 2) & ")"

Me.RecordSource = MySQL
Else
   MsgBox "There are no values to search for."
EndIf

您只需遍历数组并将每个值添加到 WHERE 字符串。您必须指示您的用户(通过表单上的标签)使用逗号分隔值。

于 2013-08-21T19:31:32.710 回答