Access 2010 includes a new control type, called a web browser control, which you can use on both web forms and client forms in your database. A web browser control displays the content of web pages directly inside a form. You can use a web browser control, for example, to display a map of an address stored in a table. You can optionally bind the web browser control to a field in your form’s record source by using the Control Source property of the control. You can also use a web browser control to display a static web page, such as a link to a specific website (for example, http://www.AccessJunkie.com), or you can use a web browser control to display a video hosted on a web page.
The Contacts Navigation sample web database (ContactsNavigation.accdb) you’ve been working with in the last section includes a web browser control on one of the forms. Open this database (if you’ve closed it) and then open the frmContactDetails form in Layout view. This form displays all the detail information about each contact in the database on the General tab of the tab control. Click the Map tab on the tab control, and Access displays a map of the contact’s address using Bing Maps, as shown in Figure 15-61. If you navigate to different records using the navigational buttons at the bottom of the form, you can see the map change to display the current contact’s address.
If you look to the right of the web browser control, you’ll see a text box control that displays a Uniform Resource Locator (URL) to the Bing Maps website. This text box is bound to a field in the Contacts table called MapAddress. The MapAddress field is a Calculated data type that concatenates the URL to the Bing Maps base website along with the Address, City, and StateProvince fields from the contact’s record. The completed URL is what you see displayed in the text box control on the form. (You can open the Contacts table in Datasheet view and examine the expression we used by selecting the MapAddress field, and then clicking the Modify Expression button in the Properties group on the Fields tab.) The web browser control is also bound to the MapAddress field. When you navigate to a different record, Access fetches the data from the MapAddress field, sends a request to that completed URL, and then displays the result in the web browser control.
To view a website in a web browser control in Access, you must enable the content of the database. The simplest way to trust this database is to click the Enable Content button on the Message Bar. You can also go to the Trust Center and mark the folder containing this database as Trusted. Click the File tab on the Backstage view and then click Options. In the left column, choose Trust Center and then click Trust Center Settings. In the Trust Center dialog box, select Trusted Locations in the left column and then click Add New Location. Add the folder containing this sample database to the Trusted Locations list. For more information on enabling content in a database, see Understanding Content Security.
Let’s create a new form with a web browser control so you can see how to work with this new control. First, close any objects you have open in the database. Next, open the Contacts table in Datasheet view and tab into the MapAddress field for one of the records in this table. Finally, click the Copy command in the Clipboard group on the Home tab to copy one of these address URLs to the Clipboard. (We’ll use this URL as an example in just a moment.) Close the Contacts table and then click the Blank Form command in the Forms group on the Create tab to create a new blank web form in Layout view. Make sure you have Control Wizards enabled in the Controls group on the Design tab, select the Web Browser Control button in the Controls group, and then click in the form grid. Access adds a new web browser control to the form grid and then opens the Insert Hyperlink dialog box with the Hyperlink Builder button selected, as shown in Figure 15-62.
Why can’t I see web browser control listed in the Controls group?
If you are working with a continuous form in Design or Layout view, Access does not display the Web Browser Control button in the Controls group on the Design tab. Web browser controls are not supported in the Detail section of continuous client or web forms, so Access does not display that control in the Controls group. If you want to display a web browser control in the form Header section of a continuous form, change the Default View property of the client form to Single Form, drop the web browser control in the form’s Header section, and then change the Default View property back to Continuous Form. If you have a web browser control in the Detail section of a client datasheet form, Access does not display the web browser control when you view the form in Datasheet view.
Figure 15-62. Access opens the Insert Hyperlink dialog box when you place a web browser control onto the form grid.
You used the Insert Hyperlink dialog box before when you studied how to insert and edit hyperlinks in Chapter 12. You can use the Hyperlink Builder button in this dialog box to help break down a URL that includes parameters into the base URL, paths, and parameters. You’ll notice the Text To Display box at the top is disabled when you build a hyperlink for a web browser control. There is really no need to have a text to display information for a web browser control when Access displays the contents of the web page inside the form. In the Address field, you can type in a website address.
You should still have the URL of one of the contact addresses in your Clipboard, so press Ctrl+V to paste that address into the Address field on the Insert Hyperlink dialog box. (The Insert Hyperlink dialog box is a pop-up form, so you cannot click the Paste command on the ribbon to perform this operation.)
When you tab out of the Address text box, Access breaks down the various parts of the URL, as shown in Figure 15-63. Access displays the base URL in the Base URL text box, any paths in the Paths list box, and any parameters in the Parameters list box. In Figure 15-63, you can also see that Access displays the name and value of each parameter in the Parameters list box. You can type a new value in the list box and Access saves the information into the completed URL. This feature is especially helpful when building complex URLs that include different parameters. (If you like, try entering your address information into the Value field next to Where1 under Parameters.) You can also click the button to the right of the Base URL text box to open the Expression Builder if you’d like to build an expression.
Figure 15-63. Access can break down a URL into its various parts using the Hyperlink Builder on the Insert Hyperlink dialog box.
Click OK to save your changes in the Insert Hyperlink dialog box and then resize the web browser control so it is bigger than the default size Access created. You should now see the web browser control pointing to the Bing Maps website, with a map displaying the address you provided, as shown in Figure 15-64. Note that if the address is invalid one, you’ll see a generic page for the Bing Maps map control. Click the Save button on the Quick Access Toolbar and name your form WebBrowserForm. You can find this form saved as frmXmplWebBrowserForm in the sample database.
Figure 15-64. Access displays the web page content of the Bing Maps site in the web browser control.
Click the Property Sheet button in the Tools group on the Design tab, and let’s take a quick look at some of the properties for the web browser control. In the Control Source property for the web browser control, you can see that Access saves the URL you provided on the Insert Hyperlink dialog box, as shown in Figure 15-65. If you are typing a URL directly into the Control Source, you must start the expression with an equals sign (=) and enclose the URL in quotation marks.
You can also bind a web browser control to a field in the form’s record source by selecting a field from the drop-down list on the Control Source property. (You can look at the Control Source property of the web browser control on the frmContactDetails in this database for an example of this.) Note that the form must be bound to bind the web browser control to a field.
You can choose to turn off displaying scroll bars for the web browser control by changing the Scroll Bars Visible property from Auto to No. In client forms, you can also set the Scroll Bar Top and Scroll Bar Left properties of the web browser control to automatically scroll the web content to a specific area of a web page. The Scroll Bar Top and Scroll Bar Left properties of web browser controls on client forms take values in pixels to scroll the window down or to the right. By default, these properties are set at 0 pixels.
Figure 15-65. You can set the Control Source property of web browser controls to a URL or bind it to a field in the form’s record source.
You can see another use for web browser controls by opening any of the five sample web templates that come with Access 2010. If you look at the Getting Started tab of any of the sample web templates, you’ll see that the forms use a web browser control to point to a video stored on a web page that displays help content on how to use the templates.
This is the last chapter about designing forms for desktop applications and web applications. You’ll learn some additional design techniques that you can automate with macros in Part VI and with Visual Basic code in Chapter 25.