How to change report orientation on MS Acces? - vba

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!

Related

MS Access: Unbound fields in a subform not showing on a report

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

MS Access will occasionally remove checkboxes from my Yes/No fields and replace them with 0 and -1

My new database is built using a variety of queries and tables. These tables and queries have two checkbox fields that are set for "Test" and "Approved". The way that these come into play is that I have buttons on one form called "ApprovalForm" that open up another form called "ViewForm". The goal was that "ViewForm would change its subform's source object every time one of these buttons is clicked. ApprovalForm closes itself first, then ViewForm opens, then Subform.SourceObject is updated to the query specified by whatever button was clicked.
Private Sub View_NonSize_APL_Click()
On Error GoTo View_NonSize_APL_Click_Err
DoCmd.Close acForm, ("ApprovalForm")
DoCmd.OpenForm ("ViewForm")
Forms!ViewForm!View_Subform.SourceObject = "Query.NonSize - APL View"
Forms!ViewForm!View_Subform.Form.Requery
Forms!ViewForm.Form.Requery
Forms.ViewForm.Caption = "NonSize - APL View"
View_NonSize_APL_Click_Exit:
Exit Sub
View_NonSize_APL_Click_Err:
MsgBox Error$
Resume View_NonSize_APL_Click_Exit
End Sub
With the process finished, the final result should be that the fields are populated by the query, which is looking at a table off on the side. The user has no access to the table itself, just that specific select query. However, in rare occasions, the checkboxes will not load correctly, instead displaying as 0s and -1s. What is peculiar about this is that when you click the button on "ViewForm" that leads back to "ApprovalForm" and click the same exact button AGAIN, the checkboxes load correctly.
My guess is that it has something to do with how "ViewForm" loads in, and due to it being a business project, the computer that it is working on is less than optimal. I tried to remedy the situation by using "Requery" and "Refresh" in the code to hopefully reload the process. I have also tried the cumbersome route of having the form close after being loaded and immediately reloading again. (Open the form, load its query, close the form, then open the form again.) That actually proved to ruin the entire process.
Is there anything I can do to counter this problem?

Display a MS Access Report using VBA

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

Hide chart in Pentaho Report Designer if not data

We are setting a chart on Pentaho Report Designer 5.3 and we want it to hide if no data is returned by the query, aligned to that chart.
We have used, the:
=NOT(ISEMPTYDATA())
in the visible style expression but it shows
chart_user_no_data_available
on the chart, and it is not working.
How do I solve this?
You can define a function that returns true/false. True means "have data", False means "No Data". Then, write in the visible style expression the following code :
=YourFunction

Creating a form where user inputs start and end dates of a report

I am working on MS Access 2007.
I am trying to create a form where the user will input 2 dates - a start date and an end date. I want these dates to become the boundaries of a report.
For example if the user inputs 01/03/14 and 10/03/14, I want Access to create a report of the data (eg Selling Price) between these two dates.
How can I do this?
There are a few ways to perform this.
The easiest, and most straight forward, in my personal opinion, involve creating a form where the user(s) will be entering Start/End dates, using a query that captures all of the information necessary for your report (including your date parameters), and the report with your query as the recordsource.
Form
Create a form with 2 text box controls: Name them whatever you like (StartDateTxt, EndDateTxt, for example), and a button control.
Query
Now, create a query, that retrieves all of the correct information you need for this report. I know you said selling price, for starters.
For the date fields you want to narrow down your search by, you need to put them in the WHERE clause or the Criteria field in QBE. It might look something like:
[Forms]![YourFormName]![StartDateTxt] and [Forms]![YourFormName]![EndDateTxt]
Note: Referencing fields can sometimes be tricky.
Report
Next, you need to create a report. If you're new to this, you can use the Report Wizard located at: Create - Reports section - Report Wizard.
You can select your query from the dropdown list on the first prompt, and add the fields you desire/need. Click next: Here you can sort your order of appearance on the report. Click next: Then you can justify your layout - if you aren't familiar with the differences, you can play around with them. Click next: Select a 'theme' to be applied to your report (font/colors, etc). Click next: Then you can either preview the report or Modify the report's design. (Really, you can do either, by clicking either button and clicking print preview or design view.)
If you click on Preview the report - Access should ask you for any parameters your underlying query requires.
Back to the form.
Right click on your button control. -> Properties -> Event -> OnClick -> click the [...] icon to the very right of the row. Select code builder.
VBA
In-between Private Sub and End Sub, you're going to write
DoCmd.OpenReport "YourReportName"
You can also check to make sure your report isn't already open.
Dim ReportName As String
ReportName = "YourReportName"
If CurrentProject.AllReports(ReportName).IsLoaded Then
DoCmd.Close acReport, ReportName
End If
DoCmd.OpenReport ReportName, acViewPreview
I hope this helps you/answers your question.
Edit: If anyone wants to edit/add on to this either by means of clarification or another alternative approach, please feel free. Just let me know.