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.
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 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'm having a bit of trouble figuring out how to fix an issue with my MS Access database report output.
First:
There are three forms, one of which is for navigation purposes (HOME) that has two navigation buttons in a navigation control (which link to either of the two other forms) and on subform field I use much like an iframe. There are also two reports, one for each of the other forms.
Second:
Both forms have unbound text fields that need to be printed onto the report output. There is no need for these fields to be saved or put into a table. The values of these forms are printed without issue when the form is isolated (i.e.- modal, form view, etc.). The unbound fields are part of the main body of the form where controlled fields are located.
Only when a form is viewed in the "HOME" form in the subform box/iframe does the report show #Name? instead of their intended values. Also worth noting, the subform does not have the Link Master Fields or Link Child Fields options.
The code used on the print command object/button is as follows and is located on the footer of the non-HOME forms:
Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[CustomerID] = " & Me.[CustomerID]
DoCmd.OpenReport "TransferAgreement_EC", acViewPreview, , strWhere
End If
End Sub
Any suggestions? I tried searching here and Googled the issue, but I haven't quite found the solution to my problem. Thanks in advance for your input!
Okay. So, found the solution by just running a whole lot of experiments and this fixed it.
On the report itself, on the data field needs to call to both the navigation form and the subnavigation box, then point to the unbound field. For example, one field in the control source is:
=[Forms]![Home]![NavigationSubform].[Form]![GCSerial_1]
Home = The navigation form
NavigationSubform = The nagivation subform box (what I consider an "iframe")
Form = Just a call to to a form, not specific
GCSerial_1 = The unbound text field
In this way, the report will not print the unbound fields when it is not a subform of the navigation form. For example, by default my two other forms are modal pop ups. When I "form view" them as modal prompts, the unbound fields display #Name? when I click my print command button, which specifies a report (no longer) contingent on a subform and not an isolated form.
THANKS FOR THE HELP AND INSPIRATION! <3
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
I want to create a Microsoft report in which should contain only one text-box and the text will be able to modify...
I have added a report WITHOUT using wizard. and have only one text-box on the report in the body section...
I wish to edit the text at run time but
me.reportviewer1.controls("textbox1").text= myrequiredtext
doesnt work...
I also tried
me.reportviewer1.controls("body").controls("textbox1").text = myrequiredtext
still doesnt work...