Access form button to generate and filter existing report

后端 未结 1 956
终归单人心
终归单人心 2021-01-23 22:13

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

1条回答
  •  北海茫月
    2021-01-23 22:47

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

    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 & "'"
    

    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
    

    0 讨论(0)
提交回复
热议问题