访问表单按钮以生成和过滤现有报告 [英] Access form button to generate and filter existing report

查看:61
本文介绍了访问表单按钮以生成和过滤现有报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,可为我的用户提供休假时间摘要(关联摘要").我也有一个报告,该报告以报告格式生成用于电子邮件和打印的摘要信息(摘要).两者都可以独立工作,并且摘要基于ComboBox选择单个用户,并且报表将拉动所有用户.我正在寻找一种在表单(关联摘要)上放置命令按钮的方式,以打开报表并将其(筛选)过滤到当前显示在表单(关联摘要)上的用户名.我已经使用命令按钮修改了表单并添加了此代码.

I have a form that provides my users with a summary of vacation time (Associate Summary). I also have a report that generates the summary information in report format for email and printing (Summary). Both work fine independently with the summary selecting the individual user based on a ComboBox, and the report pulles all users. I am looking for a way to place a command button on the Form (Associate Summary) to open and filter the report (Summary) to the user name that is currently displayed on the Form (Associate Summary). I have modified my form with a command button and added this code.

Private Sub Command22_Click()
   DoCmd.OpenReport "Summary", acViewPreview, , "Name = " & Me.Combo8     
End Sub

除了要求我输入报告名称外,此方法有效.然后,它生成了我想要的.假设与组合框关联的多个值是问题,我尝试将其调整为一个没有组合框的字段.

This worked with the exception of asking me to type in teh name for the report. Then it generated just as I want. I tried adjusting to a field that wasnt a combo box assuming that the multiple values associated with the combo box were the problem.

Private Sub Command22_Click()
   DoCmd.OpenReport "Summary", acViewPreview, , "Name = " & Me.Text12     
End Sub

Text12是将两个字段用逗号连接起来的表达式.

Text12 is an expression joining two fields with a comma.

=[Last] & ", " & [First]
result... Doe, John

现在,当我使用命令按钮时,我将收到带有以下错误的调试信息.

When I use the command button now I recieve a debug with the following error.

Run-Time error '3075':
Syntax error (comma) in query expression '(Name = Doe, John)'.

想法...

推荐答案

使用OpenReport方法的WhereCondition参数过滤报表的记录源.

Use the OpenReport method's WhereCondition parameter to filter the report's record source.

因此,假设表单中有一个名为txtUserName的文本框,并且报表的记录源包含一个名为user_name的字段,请在命令按钮的单击事件过程中使用以下类似内容:

So, assuming the form has a text box named txtUserName and the report's record source includes a field named user_name, use something like this in your command button's click event procedure:

DoCmd.OpenReport "YourReportName", _
    WhereCondition:="user_name='" & Me.txtUserName & "'"

实际上,您可以使用字符串变量保存 WhereCondition 来简化故障排除过程.

Actually you can make troubleshooting easier by using a string variable to hold WhereCondition.

Dim strWhere AS String
strWhere = "user_name='" & Me.txtUserName & "'"
Debug.Print strWhere ' <-- use Ctrl+g to open Immediate window and view this
DoCmd.OpenReport "YourReportName", WhereCondition:=strWhere

这篇关于访问表单按钮以生成和过滤现有报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆