Using the WebBrowser Control
The Microsoft WebBrowser control is an ActiveX control that you can use on your application's forms to browse Web sites, view Web pages and other documents, and download data located on the Internet. The WebBrowser control is useful in situations where you don't want to disrupt the work flow in your application by switching from Microsoft Access to a Web browser or other document-viewing application.
The WebBrowser control can display any Web page that Microsoft Internet Explorer version 3.0 can display. For example, the WebBrowser control can display pages that include any of the following features:
Standard HTML and HTML enhancements, such as floating frames and cascading style sheets
Other ActiveX controls
Most Netscape plug-ins
Scripting, such as Microsoft Visual Basic Scripting Edition (VBScript) or JavaScript
Java applets
Multimedia content, such as video and audio playback
Three-dimensional virtual worlds created with Virtual Reality Modeling Language (VRML)
In addition to opening Web pages, the WebBrowser control can open any ActiveX document, which includes most Microsoft Office documents. For example, if Microsoft Office is installed on a user's computer, an application that uses the WebBrowser control can open and edit Microsoft Excel spreadsheets, Microsoft Word documents, and Microsoft PowerPoint presentations from within the control. Similarly, if Microsoft Excel Viewer, Microsoft Word Viewer, or Microsoft PowerPoint Viewer is installed, users can view those documents within the WebBrowser control.
With the WebBrowser control, users of your application can browse sites on the World Wide Web, as well as folders on a local hard disk and on a local area network. Users can follow hyperlinks by clicking them or by typing a URL into a text box. Also, the WebBrowser control maintains a history list that users can browse through to view previously browsed sites, folders, and documents.
Note   Additional ActiveX controls that you can use to work with content on the Internet or an intranet are available in Microsoft Office 97, Developer Edition.
Adding the WebBrowser Control to a Form
Before you can add the WebBrowser control to a form, you must have Microsoft Internet Explorer version 3.0 installed.
If you purchased Microsoft Access 97 on CD-ROM, you can install Microsoft Internet Explorer version 3.0 from the Iexplore subfolder in the ValuPack folder on the Setup CD-ROM. If you are running Windows 95, run Msie30.exe to install Microsoft Internet Explorer. If you are using Windows NT Workstation, run Msient30.exe.
If you purchased Microsoft Access 97 on floppy disks, or if you prefer to install from the Web, you can download and install Microsoft Internet Explorer version 3.0 from http://www.microsoft.com/ie/download/.
Once you have Microsoft Internet Explorer version 3.0 installed, the WebBrowser control is automatically registered and is available in form Design view.
  To add the WebBrowser control to a form
1   Open the form in Design view.
2   In the toolbox, click the More Controls tool.
A menu appears that lists all the registered ActiveX controls in your system.
3   On the menu of ActiveX controls, click WebBrowser Control.
4   On the form, click where you want to place the control.
5   Move and size the control to the area you want to display.
Tip   If the WebBrowser control can't display the full width or height of a Web page or document, it automatically displays scroll bars. However, in most cases, you should make the control wide enough to display the full width of a typical Web page so that users of your application don't have to scroll horizontally.
Displaying Web Pages or Documents in the WebBrowser Control
To display a Web page or document in the WebBrowser control, use the Navigate method in Visual Basic. The syntax for the Navigate method is:
object.Navigate URL
Object is either the name of the WebBrowser control on your form or an object variable that refers to it, and URL is a string expression that evaluates to a valid URL or path. URL can refer to a Web page or other content on the Internet or an intranet, as well as to an Office document, such as a Microsoft Word document.
If URL refers to an Internet protocol and a location on the Internet, Microsoft Access must establish a connection before is can display the document. If the computer running your application is connected to a proxy server (a secure connection to the Internet through a LAN), or if it has a direct connection to the Internet, the WebBrowser control downloads and displays the Web page or other Internet content immediately. If the computer running your application uses a modem and dial-up connection to the Internet, and that connection hasn't been established beforehand, the WebBrowser control initiates the connection. For example, if the user's computer uses a modem and The Microsoft Network to connect to the Internet, the Sign In dialog box is displayed to establish the connection to the Internet before the WebBrowser control can display Internet content.
If URL refers to an Internet protocol and a location on an intranet server, the computer running your application must be connected to the intranet and have permission to access that server.
If URL refers to a standard file system path on a local hard drive or intranet, the WebBrowser control opens the document and displays it immediately. The WebBrowser control can open Microsoft Office documents, text files, and HTML documents that don't require features supported only by an Internet server. For example, the WebBrowser control can't open HTML documents that use IDC/HTX files or ActiveX Server (ASP) files from the standard file system, but it can open HTML documents that contain only the HTML tags supported by Microsoft Internet Explorer version 3.0.
Note   If URL refers to a path in the standard file system that doesn't refer to a file name (for example, C:\Windows\System\), the WebBrowser control displays the file system itself, much like My Computer.
Displaying a Document in the WebBrowser Control by Using an Address in a Text Box
Using the WebBrowser control, you can create a form that performs most of the functions of Microsoft Internet Explorer version 3.0. For example, the following illustration shows the Browse Web form in the Developer Solutions sample application.
When a user types a valid URL in the text box at the top of the form (txtLinks) and presses ENTER, the WebBrowser control (ActiveXCtl1) displays the Web page or document. Pressing ENTER triggers the AfterUpdate event of the txtLinks text box; the AfterUpdate event contains the following code which navigates to the URL entered by the user:
Private Sub txtLinks_AfterUpdate()
On Error Resume Next
  If Len(Me!txtLinks) > 0 Then
     Me!ActiveXCtl1.Navigate Me!txtLinks
  End If
End Sub
Error handling is passed to the control itself because it displays the same error messages displayed by Microsoft Internet Explorer version 3.0.
If you prefer to start navigation by clicking a command button instead pressing ENTER, you can use similar code in the button's Click event.
The Home, Back, Forward, Refresh, and Search buttons on the Browse Web form use the corresponding GoHome, GoBack, GoForward, Refresh, and GoSearch methods of the WebBrowser control.
See Also   For information on how to view brief descriptions about the properties, methods, and events of the WebBrowser control, see "Viewing Descriptions of the Properties, Methods, and Events of the WebBrowser Control" later in this chapter.
With the Save Location button on the Browse Web form, you can save the address and a description of the current document to the Links table in the Developer Solutions database. When you click the Save Location button, Microsoft Access checks to see if the URL has been saved previously, and if not, uses the following statement to open the Save Location To Table dialog box:
DoCmd.OpenForm "frmSaveURLDialog", acWindowNormal, , , acFormEdit, acDialog, _
  ctlHyper.LocationName & ";" & ctlHyper.LocationURL
The last argument of this statement (ctlHyper.LocationName & ";" & ctlHyper.LocationURL) sets the OpenArgs property to a concatenated string that contains the two values returned by the LocationName and LocationURL properties of the document currently displayed in the Browse Web form. When the Save Location To Table dialog box opens, code in its Load event parses the OpenArgs property value back into two parts and displays them as the default description and address. When the user clicks OK, the description and address in the Save Location To Table dialog box form are saved in the Hyperlink and Description fields in the Links table.
See Also   For more information on the Browse Web form, open the Developer Solutions sample application located in the Samples subfolder of your Office folder.
Displaying a Document in the WebBrowser Control by Using a Hyperlink Stored in a Table
Using the WebBrowser control, you can create a form that displays documents specified in hyperlinks stored in a table. For example, the following illustration shows the Browse Table form in the Developer Solutions sample application. You can use the Browse Table form to browse addresses saved in the Links table.
When a user clicks a record navigation button at the bottom of the form to move to a new record, code in the form's Current event displays the Web page or document whose address is stored in the current record.
If a user enters or edits data stored in a Hyperlink field from a datasheet or form, it may contain up to three parts of information separated by the pound sign (#). Even if the user doesn't enter all three parts in the datasheet or form, Microsoft Access automatically stores pound signs in the field. If there are pound signs in the Hyperlink field, you can't pass the data from the field directly to the Navigate method. To handle this, the code in the Browse Table form's Current event passes the stored value to a parsing function to separate the three parts, and then passes the appropriate URL to the Navigate method.
If you use code to enter the data stored in a Hyperlink field, as is done with the Save Location button on the Browse Web form, Microsoft Access doesn't automatically save pound signs in the field. However, because a user can edit the address displayed in the Save Location To Table dialog box, it's possible that a user familiar with the Hyperlink field's stored format could enter pound signs to delimit the display text, address, or subaddress.
Note   You don't have to store addresses in a Hyperlink field if you don't need users to be able to navigate to addresses by clicking them in datasheets or forms, or if you don't need to save addresses as HTML anchor tags when saving as HTML. As long as an address doesn't exceed 255 characters, you can store it in a Text field. If an address exceeds 255 characters, you can store it in a Memo field. In either case, you can pass the value stored in the field directly to the Navigate method.
See Also   For more information on the Browse Table form, open the Developer Solutions sample application located in the Samples subfolder of your Office folder. For more information on the format of data stored in a Hyperlink field, see "The Hyperlink Field Storage Format" earlier in this chapter.
Viewing Descriptions of the Properties, Methods, and Events of the WebBrowser Control
Like built-in Microsoft Access objects, the WebBrowser control has properties that your application can set or read to determine the control's characteristics, methods that your application can use to perform operations on the control, and events your application can respond to. You can view brief descriptions of the properties, methods, and events of the WebBrowser control by using the Object Browser.
Important   In order for these properties, methods, and events to appear in the Object Browser, you must set a reference to the Microsoft Internet and Shell Controls object library. To set this reference, open a module, click References on the Tools menu, and select the Microsoft Internet and Shell Controls check box in the Available References box.
  To view descriptions of the WebBrowser control's methods, properties, and events
1   Open a module.
2   On the View menu, click Object Browser.
3   In the Project/Library box, click SHDocVw.
4   In the Classes box, click WebBrowser.
The Members Of box lists the methods, properties, and events associated with the WebBrowser control.
See Also   For more information on the methods, properties, and events of the WebBrowser control, see http://www.microsoft.com/intdev/sdk/docs/iexplore/. If you purchased Microsoft Access 97 on CD-ROM, you can view a Help file that contains this information by opening the \ValuPack\Access\Webhelp folder on the Setup CD-ROM, and then copying the Iexplore.hlp and Iexplore.cnt files to your hard disk.
Distributing the WebBrowser Control with Your Application
Unlike most other ActiveX controls, you can't install the WebBrowser control by itself. For an application that uses the WebBrowser control to work, Microsoft Internet Explorer version 3.0 must also be installed on the computer. Microsoft Internet Explorer version 3.0 can be distributed freely, and doesn't require the payment of royalties or other licensing fees.
See Also   For information on installing Microsoft Internet Explorer version 3.0, see "Adding the WebBrowser Control to a Form" earlier in this chapter.
© 1996 Microsoft Corporation. All rights reserved.