Using VBA to assemble a report and display on-screen.
If Me.Frame15.Value = 1 Then
DoCmd.openreport "Inspections due"
End If
When this is run, it sends the report to the printer, rather than displaying on screen. Is this due to a setting in the report, or an incorrect command?
You need to tell Access that you want to view the report. As you've found out, using DoCmd.openreport without any additional variables other than the form name attempts to print the form.
You can use acViewReport as per se:
DoCmd.openreport "Inspections due", acViewReport
Related
I have a form with combo boxes rounding down selection of records from a table and a button which generates report based on selected record via VBA command, all of it works fine, except that generated reports are horizontal by default, is there any way to change default orientation or some simple command that would rotate the report in MS Access? In essence I want my report to be like in picture no. 2
Report generating code that I'm using:
DoCmd.OpenQuery "DATA", acViewPreview
DoCmd.SelectObject acQuery, "DATA"
RunCommand acCmdNewObjectAutoReport
DoCmd.Close acQuery, "DATA"
What I am getting
What I want to get
Go to Design View -> Page Settings -> Page Layout -> Vertical
See the screenshot below:
Now change the size of your report by making it smaller in width.
That's it!
I have created an Access report, with a sub report.
When emailing the report, the email button on the report removes the "sample" watermark before emailing a PDF copy. My VBA works fine on the main report, but I'm struggling to get it working on the sub-report when not hard-coding the report name.
The main report shows pages 1 and 2, the sub-report is for page 3 (p3).
The following is working to hide the watermark on the sub-report:
Me.rptTermsReport1_p3.Report.imgSample3.Visible = False
Since I have about 40 reports, I don't want to hard-code the sub-report names, but use a TempVar for the report name (e.g. rptTermsReport1 & append (_p3)
I have tried the following (and a few variations), but the TempVars and the concatenated _p3 is not working:
Report ("[TempVars]![ReportName]" & "_p3") & .imgSample3.Visible = False
The error is: "Compile error: invalid or unqualified reference" and it's the [reportname] that's highlighted.
Any ideas how you can use a TempVar with a concatenated string (_p3) linking to a field on a sub-report?
Don't put "" around variables.
.<Control> mustn't be concatenated, but used directly.
To access a variable report, use the Reports collection
If these aren't subreports, this should work:
Reports([TempVars]![ReportName] & "_p3")!imgSample3.Visible = False
If they are subreports, see:
Refer to Form and Subform properties and controls
(just replace Forms by Reports)
I have an existing Access report that runs off a Query. In the existing report I have the parameters set with brackets; [CSRName], [StartDate], and [EndDate]. I have those parameters being filled form a form using the VBA below;
All of this works just fine. My problem is this; I have this query counting the total number of errors a CSR makes. I can easily display in the report the total number of errors. What I'd like to do is have another textbox on the report that shows the total number of completed items by the CSR. In order to do this I need to embed the Control Source for the textbox with another query. I have that query written and it works outside the form. What I need to do though is pass the same parameters that I am using to generate the report into this embedded query on the report. I can't figure out how to do that. I can pass the parameters to the report itself, and it works fine, but trying to do the same won't pass the parameters to the embedded query in the report. It keeps popping up an input box and asking me to give it the variables.
I assumed I could treat the embedded query the same that I could the query the report is based off, so I used the same process to try to pass the parameters to it as well, but it did not work.
Private Sub RunQuery_Click()
DoCmd.SetParameter "CSRName", Me.CSRNameCB
DoCmd.SetParameter "StartDate", "#" & Me.StartDate & "#"
DoCmd.SetParameter "EndDate", "#" & Me.EndDate & "#"
DoCmd.OpenReport "rpt_CSRErrorTracking", acViewPreview
End Sub
What I need is the method to pass the parameters from the form to both the query that the report is based off, and the query embedded in the report itself.
How about having the queries that the report and report field are based on store the "link" to the form's fields something like this (query by form concept)...
In the query's criteria for an appropriate field:
= [Forms]![MyForm]![CSRNameCB]
And:
Between [Forms]![MyForm]![StartDate] And [Forms]![MyForm]![EndDate]
And then on the form that opens the report you don't have to set any parameters at all.
I have a report that runs from a query. The query does use a global variable but this is not the problem but needed for the explanation. The function for the variable is:
Function Var1() As String
Var1 = strVar1
End Function
The query where statement is:
WHERE (((IIf([MinOfDueDayMin]<0,0,Int([MinOfDueDayMin]/7)+1))<Var1()+1) AND ((tblEquipment.Retired)=False))
which uses the var1 function
The criteria is on a field that is actually a calculation and that is where I think the problem starts.
The report is run for a command on another form using the following code:
strVar1 = InputBox("Enter Number of Weeks for report")
If strVar1 = "" Then Exit Sub
DoCmd.OpenReport "rptEquipPmSchedule", acViewReport
Everything works just fine
On the report I have a double click event that opens a form. This form uses part of the same query. (not the same one but two levels higher) thiS allow the user to change things so i expect to use requery for the report.
If i double click and then not even change anything and then go back to the report I have #ERROR in the fields that have the calculations
i put a me.requery in the activate event of the report. this did not work.
So I tried a work around.
When I double click the report field, i close the report and send the strVar1 value to the form that is opened. then when I close the form I reasign the strVar1 just in case it is lost be an assignment by another user (currently I am the only one using this but did it just to be sure it had the correct value.) Then I open the report again but still get the errors. I did not expect this at all. thought starting the report from scratch would certainly work. I even closed the form just after assigning strVar1.
then in final effort. When I close the form I run the exact same code:
strVar1 = InputBox("Enter Number of Weeks for report")
If strVar1 = "" Then Exit Sub
DoCmd.OpenReport "rptEquipPmSchedule", acViewReport
Which will force the user to input the value for strVal1. Even though this is not what I want but tried this for troubleshooting and I still get #ERROR.
When I run the report for a form that does not have any of the same field, no issues. When I run the report or keep it open with a requery from the form that has the same data, the report will not give the correct results. Note that if I run the query itself, the data in the query is correct.
i also tried using a number instead of Val1() in the query and got the same results.
i also tried the refresh button in the ribbon and get Unknown Function Name and all the data in the report is lost.
Anyone got any ideas??
While your textual explanation is difficult to understand the entire scope, consider re-assessing your workflow. The entire objective is to allow users to run customized criteria for reporting. And your main issue is the strVal does not persist in memory so all references to it fails.
Consider the following points:
Have users set criteria on a dedicated unbound form with button click for report where that report instance is immutable for viewing/printing only and if needed to be changed must be re-run (i.e., button re-clicked).
Access has no need for VBA's InputBox() as strVal can be an unbound textbox on this unbound form whose value remains intact for all open windows.
Have function and all its references point to form field: Form!myFormName!strValuetextbox
Because reports on pretty much any software/web app system is not used as a GUI interface to run actions, users will know if they intend to change report criteria, close current report or go back to entry point and change strVal then re-click button to re-run report.
Keep data entry/input (primary use of forms) separate from data export/output (like reports). From developer and user standpoint this compartmentalization will save you headaches down the road.
I am very new to Access and need a bit help over here. I was working on MS Access 2007 (in VB) with SQL 2008 Server as my database.
I am printing a report already saved on the Button Click event.
Everything is working fine, report can be printed but after printing the report it is also printing the form containing that Button.
Here is the code that I have written on Button_click:
DoCmd.OpenReport "ReportName"
DoCmd.PrintOut
any suggestions ??
DoCmd.OpenReport Method
expression.OpenReport(ReportName, View, FilterName, WhereCondition,
WindowMode, OpenArgs)
DoCmd.OpenReport, "report", acViewNormal
You should not need PrintOut.