With so many companies and individuals having presence on the internet, it is more likely that your customers could have their own web sites. If we build a Microsoft Access table that will store our Customer information, this table can easily save each Customers web site address in a single field that stores the URL.
If we want to have immediate access to the web sites as you view your customer data in a Microsoft Access form, we can view it in a Web Browser control that we place on the form design.
If we want the Web Browser control to display the customer's Web site with the current record we need to add the code required to the forms OnCurrent event procedure.
The form below shows the completed Microsoft Access form showing the Web Browser control in action:
Microsoft Access form showing the Web Browser control
In the form design, we have added the Microsoft Web Browser control, which is an Active X control available from the toolbox » More Controls option.
After adding the control, we change the name of this in the Property sheet to wbbWebsite. Now we need to add the code to the form's OnCurrent event to determine what is displayed in the Web Browser control on the form.
Using the form's OnCurrent event we have included the following code:
Private Sub Form_Current() 'Navigate to the current record's Web site 'If there's no URL stored in the field, then display Google search engine. If Len([CompanyWebsite]) > 0 Then wbbWebsite.Navigate URL:=[CompanyWebsite] Else wbbWebsite.Navigate URL:="www.google.co.uk" End If End Sub
What this will do is check the [CompanyWebsite] field that is included in the Microsoft Access table to ensure that the length Len([CompanyWebsite]) > 0 , if so the web browser control (wbbWebsite) will navigate to the URL displayed in the CompanyWebsite field.
Using the If...Then...Else statement, we are checking if the CompanyWebsite field length is greater than zero, if not we will display a default web page (www.google.co.uk)
This example assumes that you have a current internet connection, and it should be noted that there is no error checking routines in place to prevent opening the form without this current connection being live.