Prompt User for a Custom Report Name and add it to the report before opening (1 Viewer)

kengooch

Member
Local time
Today, 00:32
Joined
Feb 29, 2012
Messages
54
I have a button on a form that allows users to create custom reports through the use of multi-select list boxes. Then there are several reporting option buttons on the form. The following code will open the report with the filtered records.

Private Sub Command202_Click()
'This Code Handles the Report based upon the Filter selections
DoCmd.OpenReport "rStfCmpltChkLst", acViewReport, , vSetFilters
End Sub


I was trying to give the user an option to create a custom report name. I added an unbound text box to the report and named it vRepTitle then added an inputbox request to prompt the user for the report name and assigned that value to vRptTitle, then I tried to pass that title to the unbound text box but it doesn't work. Here is the modified code I tried that doesn't work.

Private Sub Command202_Click()
'This Code Handles the Report based upon the Filter selections
vRptTitle = InputBox("Enter the Report Name", "Get Custom Report Name", "Default Custom Report Name")
DoCmd.OpenReport "rStfCmpltChkLst", acViewReport, , vSetFilters, vRepTitle = Me.vRptTitle
End Sub


Would appreciate corrections
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:32
Joined
Oct 29, 2018
Messages
17,524
One approach is to use the OpenArgs argument and then assign it's value to the Textbox in the Open event of the report.
 

kengooch

Member
Local time
Today, 00:32
Joined
Feb 29, 2012
Messages
54
One approach is to use the OpenArgs argument and then assign it's value to the Textbox in the Open event of the report.
I am not familiar with OpenArgs... can you explain further?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:32
Joined
Oct 29, 2018
Messages
17,524
I am not familiar with OpenArgs... can you explain further?
You could try:
Code:
DoCmd.OpenReport "rStfCmpltChkLst", acViewReport, , vSetFilters, , , Me.vRptTitle
Then, in the Open event of your report,
Code:
Me.vRepTitle = Me.OpenArgs
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:32
Joined
Feb 19, 2002
Messages
34,345
You could add the custom name box on the form as an unbound ontrol. Use the OpenArgs argument to pass the value to the report. In the Open event of the report, set the value to what is in OpenArgs:

Me.txtCustomReportName = Me.OpenArgs

Don't use prompts. Use formfields to collect the arguments. You can pass them usingOpenArgs or you can pull them in the Report's RecordSource Query:

Select fld1, fld1, fld3, Forms!yourform!txtCustomReportName As CutRptName
From YourTable

If you use the query to "pull" the variables, you can bind controls to them and you don't need code at all.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:32
Joined
May 7, 2009
Messages
14,983
you also need to make sure vRptTitle has a Value (in case Cancel button is clicked on the InputBox).
Code:
Private Sub Command202_Click()
Const sDefaultTitle As String = "Student Complete Checklist"
'This Code Handles the Report based upon the Filter selections

    vRptTitle = InputBox("Enter the Report Name", "Get Custom Report Name", sDefaultTitle)
    If Len(vRptTitle) = 0 Then
        vRptTitle = sDefaultTitle
    End If
    DoCmd.OpenReport "rStfCmpltChkLst", acViewReport, , vSetFilters, vRepTitle = Me.vRptTitle

End Sub
 

Users who are viewing this thread

Top Bottom