You can get rid of the Lines and scrollbars on a form in runtime by setting the following form property values to No:

• DividingLines: Used to separate sections on a form.

• NavigationButtons: Provides access to navigation buttons and a record number box.

• RecordSelectors: Record selectors display the unsaved record indicator when a record is being edited in Form view.

I now create a Colors program that allows a user to change the color of a label control and exit the Access application without the assistance of a control wizard. First, I create my Colors form and set the following form properties:

• Navigation Buttons:No

• Record Selectors: No

The completed

Light Switch form in Design view.

I add four command buttons (three to change colors and one to exit the application) and one label control that displays the color selected by the user:

• Caption:White

• Name:lblDisplay

• Caption:colors

The Label's BackColor property cannot be changed unless the corresponding Label's BackStyle property is set to Normal.

A picture of the Colors form in design time should look similar to that in Figure 2.5.

Private Sub cmdBlue_Click()

Me.lblDisplay.BackColor = vbBlue End Sub

Private Sub cmdRed_Click()

Me.lblDisplay.BackColor = vbRed End Sub

Private Sub cmdWhite_Click()

Me.lblDisplay.BackColor = vbWhite End Sub

The completed Colors form in Design view.

The way I used the Me keyword to access the label and its corresponding properties should not be new to you. What should have caught your attention were the values I used in assigning BackColor properties. Specifically, VBA provides you access to eight color constants:

It's important to note that BackColor and ForeColor properties actually take a number value, which each color constant stores representatively. In addition to using VBA color constants, you can assign numbers representing a multitude of colors using either the RGB function or by viewing the BackColor or ForeColor properties in design time using the Properties window.

To terminate an Access application, use the DoCmd object and access its built-in Quit method as shown in the next command button Click event procedure.

Private Sub cmdExit_Click()

DoCmd.Quit End Sub

The VBA code in cmdExit_Click() event procedure is similar to the code generated by the Access control wizard to quit an Access application using the DoCmd object and its Quit method.

T«*«c,t ^he amPersand (&) character creates keyboard shortcuts with the Alt key when iC^Ot placed in the caption property of certain controls such as command buttons.

0 0

Post a comment