Microsoft Access (and MSVB 6) ships with two main
categories of controls. Regular controls display on the Toolbox.
Additional controls are available as ActiveX objects. To access these
controls, you can click the More Controls button on the Toolbox and select
the one you want.
In this application, we will use three scroll bars to
change the color of a frame. All these controls will be positioned on a
form.
This application is simply used to take advantage of
some ActiveX controls that accompany MS Access. Most of these controls
require VBA to implement their behavior.
Practical Learning: Starting the Exercise |
|
- Start Microsoft Access and create a blank database named ColorChanger1
- On the main menu, click Insert -> Forms
- On the New Forms dialog box, make sure Design View is selected and
make sure the combo box is empty:
- Click OK
- Display the Properties window. If you are using MS Access >=
2000, on the Properties window, set the Allow All Design Changes
to Design View Only
- Save the form as frmColorChanger
- Change its properties as follows:
Caption:
Color Changer
Record Selectors: No
Navigation Buttons: No
Border Style:
Dialog
- To add the first control, while the form is selected, on the
Toolbox, click the More Controls button
- On the list, scroll down and click Microsoft Forms 2.0 Frame
- Then, click on the top-left section of the form
- Once again, on the Toolbox, click the More Controls button .
Scroll down in the list and click Microsoft Forms 2.0 ScrollBar
- Click outside of the previously added frame on the form, for example
on the right side
- Right-click the new scrollbar and click Copy. Right-click an empty
area on the form and click Paste. Paste it again to have three scroll
bars.
Design the dialog box and change the properties of the controls as follows:
|
Control |
Name |
Caption |
Min |
Max |
Value |
Align Text |
Frame |
fraPreview |
|
|
|
|
|
ScrollBar |
scrRed |
|
0 |
255 |
63 |
|
Label |
lblRed |
000 |
|
|
|
Center |
ScrollBar |
scrGreen |
|
0 |
255 |
63 |
|
Label |
lblGreen |
000 |
|
|
|
Center |
ScrollBar |
scrBlue |
|
0 |
255 |
63 |
|
Label |
lblBlue |
000 |
|
|
|
Center |
|
- While the form is still in Design View, on the Form Design toolbar,
click the Code button to
open MS Visual Basic
- In the Object combo box, select Form and implement its Load()
event as follows:
Private Sub Form_Load()
Rem Paint the frame with a default gray color
fraPreview.BackColor = RGB(192, 192, 192)
End Sub
|
- On the Object combo box, select scrRed and implement its Change()
event as follows:
Private Sub scrRed_Change()
' Create a color based on a combination of the values of the scroll bars
' Use that color to paint the frame
fraPreview.BackColor = RGB(255 - scrRed.Value, _
255 - scrGreen.Value, _
255 - scrBlue.Value)
' Show the value of red degree of the current color
lblRed.Caption = 255 - scrRed.Value
End Sub
|
- On the Object combo box, select scrGreen and implement its Change()
event as follows:
Private Sub scrGreen_Change()
fraPreview.BackColor = RGB(255 - scrRed.Value, _
255 - scrGreen.Value, _
255 - scrBlue.Value)
lblGreen.Caption = 255 - scrGreen.Value
End Sub
|
- On the Object combo box, select scrBlue and implement its Change()
event as follows:
Private Sub scrBlue_Change()
fraPreview.BackColor = RGB(255 - scrRed.Value, _
255 - scrGreen.Value, _
255 - scrBlue.Value)
lblBlue.Caption = 255 - scrBlue.Value
End Sub
|
- Test the application
- After using it, close it and return to your programming environment.
|
|