我有一个表单,用户将要在文本框中输入项目名称的部分或完整字符串值,单击表单中的按钮,然后打开仅包含按这些结果过滤的项目的报告。例如,如果我输入“ Acc”,则我的project_name字段中的所有结果将仅包含那些具有“ Acc”的结果。
我可以通过查询(Like "*" & [Enter keyword] & "*"
)使其正常工作,但是我想通过表单来实现。我也有其他一些我想做的事情,我不想为每个领域创建一个新的报告和查询。我希望能够使用VBA和表单来执行此操作。
我的代码打开了报告,但是没有结果。我什至尝试输入单个字母(即“ a”)或其他显然没有运气的字符串。这是我的代码:
Private Sub Command0_Click()
Dim stDocName1 As String, strwhere1 As String
Dim stLinkCriteria1 As String
stDocName1 = "Grantlist"
strwhere1 = project_name = "Like *'" & Me![findproject] & "*'"
DoCmd.OpenReport stDocName1, acViewReport, , strwhere1, acWindowNormal
End Sub
使strwhere1 =
单个字符串的右侧
使用只是Like
代替= Like
将单引号移到*
以下内容之前Like
strwhere1 = "project_name Like '*" & Me![findproject] & "*'"
检查您要传递到的WhereCondition可能会很有用DoCmd.OpenReport
。用于Debug.Print
在立即窗口中显示它。您可以使用Ctrl+g转到那里。
Debug.Print strwhere1
DoCmd.OpenReport stDocName1, acViewReport, , strwhere1, acWindowNormal
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句