Access VBA Macro Programming

(Joao Candeias) #1

View the form in Design View. Select all the controls you want to set to a uniform size and
alignment by dragging a box across them with your mouse. Make sure that only the controls
you want to resize are selected. They will all be shown with a colored outline and handles.
Click the Arrange tab in the ribbon. In the Sizing & Ordering group on the ribbon, you
have an icon called Align to allow you to align all your controls to left, right, top, or bottom.
This provides a drop-down of options. For example, if we have several text boxes that are
displayed in a vertical row but do not line up vertically with each other, selecting them all and
clicking the Left option of the drop-down will line them all up on the control that is furthest
left within the selection.
This sorts out the alignment, but you may also have a situation where some are different
widths or heights compared to others. In the same ribbon as for alignment is a Size/Space
icon containing a drop-down for To Tallest, To Widest, To Shortest, To Narrowest. Click this
and all the controls in the selection will be set to the same height or width according to the
icon you clicked.
The Spacing options of the Size/Space drop-down allow you to set the gaps between
controls using the Equal Horizontal and Equal Vertical icons. Controls can be easily moved
in minute increments in any direction by selecting the control and holding down theCTRL
key. If you then press any of the arrow keys while theCTRLkey is held down, your control
will slowly move in the desired direction. I have found this a really useful feature of Access
in tidying up a form and making it look more presentable to the users.
You can also change the background color of the form and individual controls by setting
the Back Color property. If you click the button with the three dots on it, you will see a
palette of colors to choose from.
If you like, you can add a picture to the background of the form as well. The Picture property
will allow you to upload a picture, which then becomes embedded in that form. This could be
a picture associated with that form or a company logo. Remember, however, that pictures
take up memory and too many can make your database unwieldy. Make sure the Selection
type is Form before having the reader look for the Picture property in the Property Sheet.
If you need other text on the form, use a label control and change the Caption property to
your text. As in all the controls, you can change the font, color, point size, and so on to suit
your needs.
You can set the Close Button property to No in order to stop the user from using the Close
button to exit your form. Bear in mind that you will need to provide them with another means
of exiting if you do this. You can also use the Min Max Buttons property to prevent the user
from changing the size of the form and you can do the same thing with the Control Box property.


Using a Custom Ribbon on the Form

When you design a form, it always looks like you are stuck with the standard Access ribbon,
but this is far from the case. See Chapter 11 on how to design custom ribbons for particular
forms. Once you have your ribbon designed, simply use the Ribbon Name property on the
form to integrate it into your form. You can even remove the ribbon totally from a form using
this methodology.


Chapter 9: Forms and Reports 107

Free download pdf