Practical Learning: Introducing Windows Controls
Creating a Button
To visually create a button, after displaying the form or report in the Design View, in the Controls section of the Ribbon, click the Button and click the form or report. To assist with the action that a button should perform, Microsoft Access provides a wizard that leads to a long list of action. You are encouraged to use that wizard. Of course, you can also take care of the actions yoursellf.
Practical Learning: Introducing Buttons
Characteristics of a Button
The Caption of a Button
The primary visual aspect of a button is its caption. To support it, the Button class is equipped with a property named Caption. To visually set the caption of a button, access its Property Sheet. In the Format or the All property page, click Caption and type a string of your choice. To programmatically specify the caption of a button, access its Caption property and assign a string of your choice. Here is an example:
Private Sub cmdToday_Click() cmdToday.Caption = "Submit Time Sheet" End Sub
Practical Learning: Setting the Caption of a Button
The Size of a Button
The size of a button is primarily managed as done for the other controls. Furthermore, you can resize a button to fit its caption, you can proceed as done for a label: Select it and double-click one of its borders.
Practical Learning: Resizing a Button
A Picture on a Button
To make your button appealing, you can make it display a small picture. To assist you with this the Button class is equipped with a property named Picture
To visually specify the picture of a button, access its Property Sheet. In the Format or the All property page, click Picture and click its ellipsis button . To assist with pictures, Microsoft Access ships with many pre-designed icons. If you click the Picture field, the Picture Builder dialog box will present a list in the Available Pictures section:
If you click an item in the Available Pictures list, its preview would display on the left side. If none of the pictures suits you, click Browse and select a picture. After selecting the picture, click OK.
You can display only the caption, only the picture, or both the picture and the caption on a button. If you decide to use both, to let you control the position of the picture with regards to the caption, the button has a property named Picture Caption Alignment in its Property Sheet.
Practical Learning: Displaying a Picture on a Button
Colors on a Button
Like all Windows controls in Microsoft Access, a button can be painted with a color specified in the Back Color field of its Property Sheet. The caption can also display with a font and a color of your choice. One way you can enhance the appearance of a button is to paint with different color based on how the user is currently using the control. To support this, the button is equipped with the following properties in the Format or the All tab of its Property Sheet:
Practical Learning: Using Colors on a Button
A web browser is a control that shows a file. The file can be a regular picture or a web document that is identified as a Uniform Resource Locator (URL). A web browser is very flexible with the type of document it can show. Still, you must follow some rules to prepare the document.
The primary type of document intended for a browser is a webpage. You probably already know how to create such a document. A browser can also be asked to display a picture. The web browser of Microsoft Windows supports various or all types of pictures, including those with the extensions .bmp, .jpg, .jpeg, .gif, .png, etc.
Practical Learning: Introducing Web Browsers
Creating a Browser
A web browser can be added to a form and not to a report. To get it, after displaying the form in Design View, in the Controls section of the Design tab of the Ribbon, click the Web Browser Control and click the form.
Characteristics of a Web Browser
The Control Source of a Web Browser
Probably the most important detail of a web browser is the document it displays. This is specified by the Control Source property. You cannot create a web browser on a table. Instead, you can create a text-based field, then use it as the record source of a browser.
When performing data entry, enter the name of the file with extension, the complete path and name of the file, or the URL of the web page that the browser would display.
Practical Learning: Using a Web Browser
Web Browser Events
The web browser has many events appropriate for its functionality:
We already know that you can submit the path of a file or a URL to a browser. When a file path or a URL is given to a web browser, before it processes it, the control fires an event named On Before Navigate2. It appears as follows:
Private Sub wbNavigator_BeforeNavigate2(ByVal pDisp As Object, _ URL As Variant, _ flags As Variant, _ TargetFrameName As Variant, _ PostData As Variant, _ Headers As Variant, _ Cancel As Boolean) End Sub
If there is no problem in this event, the control shows the file or the web page. When the control has finished displaying the document, the web browser fires the On Document Complete event. If there is a change on the document, the control fires an On Progress Change event.
When a web browser has received a file path or a URL, it makes an attempt to show that file or the web page. If it encounters a problem, it fires an On Navigation Error event.
At any time, and if you allow it, the user can change the document the control is displaying. When a new document must be displayed, the control fires an On Updated event.
If you create a form or report that has many or large objects, you can divide the form or report in sections called pages (this has nothing to do with the Page Header or the Page Footer sections of a form or report) . Then, you can ask Microsoft Access to display only the desired section when necessary. To make this possible, Microsoft Access provides a special control named Page Break.
As done for all controls, before creating a page break, you must display the form or report in the Design View. To get a page break, in the Controls section of the Ribbon, click the Insert Page Break control and click the desired section of the form or report. Normally, you should add it to the Detail section. You can add as many page breaks as you need.
Practical Learning: Introducing Page Breaks
Implementing Page Breaks
You can provide buttons that the user will click to access an area delimited by the page break. To support page breaks, the Form class is equipped with a method named GoToPage. In the same way, the static DoCmd is equipped with the same method. Its syntax is:
Form|DoCmd.GoToPage(ByVal PageNumber As Lond, _ Optional ByVal Right As Long = 0, _ Optional ByVal Down As Long = 0)
This method takes as argument the section to access. The first section, or the section above the first page breake has an index of 1, the second page break has an index of 2, and so on.
Practical Learning: Using Page Breaks