IT tutorials
 
Office
 

Microsoft Access 2010 : Enhancing Reports with VBA - WORKING WITH VBA IN REPORTS

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Product Key Free : Microsoft Office 2019 – Serial Number
11/17/2011 4:48:55 PM

1. CREATING A REPORT

There are many ways to create a report in Access 2010, including the following:

  • Using Report Designer: Using the Report Designer gives you the most control over creating reports. You can place any type of control on the design surface and bind the report to a table, query, or SQL statement. The Report Designer also enables you to add VBA code behind the report.

  • Using Layout view: The Report Designer offers a powerful way to create reports. However, as you design your reports, you may frequently need to switch between Print Preview and report design because data from the tables is not shown at design time. Layout view, as mentioned earlier, was created to solve this. With Access 2010, you can add different types of controls, apply formatting, and add sorting, grouping, and totals, all while viewing the actual data from a table or query.

  • Using Report Wizard: The Report Wizard walks you through a report creation process with a number of options from which to choose. The options include data settings such as data source; grouping and sorting; and formatting options, such as layout, orientation, and style. Using the wizard is also an easy way to create reports using multiple tables.

  • Programmatically: You can also create reports with code. Access provides a method on the Application object called CreateReport that can be used to create a report. This method is largely used when you want to create reports using your own mechanism for gathering input from the user.

  • Using Quick Reports: Click the Report button in the Ribbon's Create tab to create a new report with a tabular layout. The report includes common elements such as header and footer sections, and a count of the number of records.

2. WORKING WITH VBA IN REPORTS

More specifically, you'll explore some examples that use specific events and properties such as CanGrow and CanShrink, and then move into some of the more common types of reports that you can create with just a little VBA. Let's start with some of the basics.

To add a module to a report, simply add an event handler for an event such as Open, or set the HasModule property of the report to Yes.

2.1. Control Naming Issues

As you add controls, or even when you name fields, there are a few things to keep in mind that make the process of creating queries, forms, and reports much easier. The first is to avoid the use of spaces or punctuation in field and control names. Spaces may make your field names easier to read, but they are not user-friendly when it comes to queries or code. Consider a field named Last Name with a space in the middle. This field name must be bracketed when used in a query. Without the space, brackets are not required (although Access may add them). It turns out that brackets are also required when you refer to the field in code, so instead of referring to the field like this:

Me!LastName

you must refer to it like this:

Me![Last Name]

As you can see, using the space in the name makes it harder to read and write in code. Instead, don't use spaces in names; use the Caption property of a field or label control to change the text that is displayed.

Another issue that causes problems is circular references. A circular reference occurs when a control uses itself in an expression. Say, for example, you drag a field named LastName to a report, and then decide to change the ControlSource property for the control to:

=Left([LastName], 1)

Unless you rename this control, the LastName control will try to use LastName in the expression, which is itself an expression — in other words, a circular reference. To avoid circular references, be sure to rename the control when you modify the ControlSource. In this example, you might consider renaming LastName to txtLastName.

2.2. The Me Object

The Me keyword is used in class modules in VBA. For forms and reports, Me returns the current form or report object. For a standalone class module, the Me object returns the current running instance of the class. This is particularly useful for writing generic code. For example, if you have a procedure that changes the caption of a report based on the user who is currently logged on, and you want to write the routine so it can be used on any report, you might write this:

Public Sub SetReportCaption(objReport as Report)
' Set the report caption to the user name
objReport.Caption = Environ$("USERNAME")
End Sub

To pass a Report object from the report that is currently opened, pass the Me keyword as the parameter for the procedure. The following example uses the new Load event for a report to set the caption:

Private Sub Report_Load()
SetReportCaption Me
End Sub
 
Others
 
- Microsoft Access 2010 : Enhancing Reports with VBA - INTRODUCTION TO REPORTS
- Microsoft Word 2010 : Creating a Table of Contents
- Microsoft Word 2010 : Creating Footnotes and Endnotes
- Microsoft Visio 2010 : Tips for Creating Block Diagrams
- Microsoft Visio 2010 : Tips for Creating Network Diagrams
- Microsoft PowerPoint 2010 : Working with Images (part 3) - Modifying Images
- Microsoft PowerPoint 2010 : Working with Images (part 2) - Inserting Screenshots & Working with Photo Albums
- Microsoft PowerPoint 2010 : Working with Images (part 1)
- Microsoft PowerPoint 2010 : Using Animation Painter & Previewing an Animation
- Microsoft Excel 2010 : Using Slicers to Filter a PivotTable
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us