UNIVERSITY OF BRISTOL COMPUTING SERVICE

This document may be used wholly or in part by the academic community, providing suitable acknowledgement is made. It may not be used for any commercial or profit-making purpose without permission.

University of Bristol Computing Service. All rights reserved.

Practical Advanced Reports and Access Basic

Introduction

There are many things that one can do to help applications and here are a few listed below
Look at the design of Report1:

Summary of Report wizards

Creating a report from a form

Often the same layout is appropriate for a form and report. there are two methods to create a report like a form. Method 1: Method 2: There are a few changes to make:

Field expressions

Certain types of data work better on reports as concatenated fields. You do not need separate controls for name components, or city, postcode, so you can use a calculated field directly in a control, or as an expression in a query column, to get names and addresses to print without gaps. The iif function (arguments: condition, output if true, output if false) can be used to prevent spaces or orphan punctuation if there is missing information in any of the component fields.

The strconv function can be used to change fields that have been entered in capitals to mixed case

Varying number of lines

If there are any controls that might contain varying amounts of information (say Address or Notes)

Designing a report from scratch

Design view does not use the wizard.

Multi-column reports

HTML template files

Access Basic code

One can combine forms with Microsoft Access Basic code. Forms have procedures associated with events and saved with the form definition (as in all the following examples and the click subroutine above). To create a procedure to respond to the OnCurrent event of a form, for example, click the Code Builder button next to the OnCurrent property in the property sheet and write the desired code. The procedure is saved with the form itself. Only global procedures that is shared between forms is stored in modules. This model makes it easier to keep track of an application's code.

The following exercise shows different ways of creating a button to close a form and how to put an informative message on when the button is pressed. It also shows how using the button wizard produces default Access code and how it can be modified.

Now add an extra line before the MsgBox Err.Description statement. (This is a global error message so does not distinguish between different types of errors- so quick and easy to give your own message for putting on previous record, and next record buttons for example, when the only error is likely to be that you are already at the first record so cant go back any further.) This changes the default error message to your own message.

The following shows how to use a macro on a button to perform the same effect:

The following shows how to add informative text to a default button

The following code opens a form in Form view and moves to a new record. Note that the number of arguments to the DoCmd call reflects the arguments required on the macro call.

Common Application Design Solutions

Technique 1- Creating a Dialog Box

Technique 2- Finding a Record Based on a Combo Box Selection

Technique 3- Adding a New Record When It is Not in the List

Technique 4- Setting a Control's Record Source During Runtime

Using Access Basic to split an address into separate fields

This example shows how to split an address field up when the user has entered it in one field with each address line separated by carriage return (chr(13) )

The functions used are:

Create a query with the bad_design table to use the function:

Using Access basic to split up a person's name into separate fields

Working through Prof X Y Bloggs:
Stage 1:
get_initials is null; rest is Prof X Y Bloggs; part_initials is null; instr(rest," ") is 5 (position of first space) Stage 2:
since instr is greater than 5, rest set to X Y Bloggs using mid
Stage 3:
instr(rest) is now 2 (position of first space in rest)
enter the do loop, set part_initials to X, rest to Y Bloggs
loop
instr(rest) is now 2, set part_initials to XY, rest to Bloggs
loop
instr(rest) is now 0 so end loop, set get_initials to the value of part_initials ie XY

Database Documentor

Customising Microsoft Access

Options and Preferences

Backup

Compressing the database