|



Web Browsing within Access Form

Posted: 27 Dec 2009 06:42 PM PST


Browsing the World Wide Web is nothing new to us. But, how about organizing the Web Addresses of frequently visiting Websites in a Table and browse the Web from within an Access Form?

Form with Web Browser Control

Not only Internet Sites, you can browse the Intranet Website within your Local Area Network - Corporate LAN) too. All you have to do is to create an Access Form with a Microsoft Web Browser Control and a few lines of VBA Code.


For example, the following VBA Code will open the GMail Web Site http://www.gmail.com/ automatically when you open the Form with the Web Browser Control, as shown in the above image.:


 
Private Sub Form_Load()
Dim strURL As String

strURL = "http://www.gmail.com/"
Me.WebBrowser0.Navigate strURL
End Sub


Don't know how to do it? Try the following:

  1. Open a new Form in Design View.

  2. Click somewhere on the Detail Section of the Form to select that area.

  3. Select ActiveX Control... from Insert Menu.

  4. Look for the name Microsoft Web Browser in the displayed list of ActiveX Controls and select it.

  5. Click OK to insert a Web Browser Control on the Form.

  6. While the Control is still in selected state drag the right-bottom-corner sizing control to make it big enough on the Form so that you can view the Web Pages properly.

  7. Display the Property Sheet of the Browser Control (View - ->Properties).

  8. Change the Name Property Value to WebBrowserO to match with the name used in the above VBA Code.

  9. Select Code from View Menu to display the VBA Code Module of the Form.

  10. Copy and Paste the above Code into the Module.

  11. Save and Close the Form with the name myWebBrowser.


  12. Connect your PC to the Internet.


  13. Open myWebBrowser Form in normal View.


  14. Wait for few seconds to load the Web Page into the Control and to display.



We have used the Website Address directly in the Code. But, if you create a Table with the list of all the Website addresses that you visit very often then with a Combo Box on the Form we can select the Web address to go to that site quickly. We need to make few changes in the above Code to make it flexible.

  1. Create a Table with a single field with the following details:


  2. Table Name: WebSites


    Field Name : WebAddress Data Type : Text Field Size: 255



  3. Save the Table Structure and open it in Datasheet View.


  4. Add few records with Web URLs that you visits frequently, save and close the Table.


  5. Make a Copy of the Form myWebBrowser and name the copy as myWebBrowser2.


  6. Open myWebBrowser2 in Design View.


  7. Display the Form Header Section (View - -> Form Header/Footer), if it is not already Visible.


  8. Expand the Form Header Section with enough height to create a Combo Box Control.

  9. Create a Combo Box using the WebSites Table.


  10. While the Combo Box is still in selected state display the Property Sheet (View - -> Properties).


  11. Change the following Property Values of the Combo Box:



  12. Name : cboWeb
    Width : 5"
    Default Value : "http://www.gmail.com/" or any other Website Address Value you prefer.


  13. Select the child label attached to the Combo box and change the Caption Property Value to Web Address:

  14. Display the Code Module of the Form (View - -> Code).

  15. Copy and Paste the following Code into the Module replacing the existing lines.


  16.  
    Option Compare Database
    Option Explicit

    Dim WebObj As WebBrowser
    Dim varURL As Variant

    Private Sub cboWeb_Click()
    GotoSite
    End Sub

    Private Sub cboWebLostFocus()
    GotoSite
    End Sub

    Private Sub Form_Load()
    Set WebObj = Me.WebBrowser0.Object
    GotoSite

    End Sub

    Private Function GotoSite()
    varURL = Me!cboWeb
    If Len(Nz(varURL, "")) = 0 Then
    Exit Function
    End If

    WebObj.Navigate varURL

    End Function

  17. Save the Form and open it in Normal View.


  18. The Website address that you have inserted into the Default Value Property of the Combo Box will open up in the Browser Control.


  19. Select one of the other Website addresses you have added to the Table from the Combo Box.


  20. The Browser Window will open the new Website.


If we open other Web Pages by clicking on the Links from the displayed pages then we can navigate (go Back or Forward) between pages by adding few more lines of Code.


But, first let us have a look at the above Code to see what is happening there. We have declared a Web Browser Object Variable and a Variant Variable at the Global declaration area of the Module.


Created a separate Function GotoSite() to respond to different Events (Actions) on the Form without duplicating the Code everywhere.


For example: when we open the Form the GotoSite() Function opens the Default Value URL, we set in the Combo Box Property, through the Form_Load() Event Procedure.


When you select a URL from the Combo Box the cboWeb_Click() Event Procedure calls this Function to open the selected Web Page.


If you type a URL in the Web Address Control cboWeb and moves the Cursor out of the control the Lost_Focus() Event Procedure runs the Function to open the URL you typed on the Address Control.


We will create few Command Buttons on the Header of the Form, as shown to the right of the Combo box Control on the above design and write Subroutines with some simple Browser Object Commands to navigate between Web Pages, which we may open from the displayed Web Pages.




  1. Open myWebBrowser2 Form in Design View.


  2. Display the Toolbox (if it is not visible then select Toolbox from View Menu.


  3. Create five Command Buttons to the right of the Combo Box.


  4. Display the Property Sheet of the first Command Button and change the Name Property and Caption Property Values to Home.


  5. Similarly, change the Name and Caption Property Values of the other Command Buttons with the values given below.


    • Back


    • Forward


    • Refresh


    • Stop



  6. Display the Code Module of the Form (View - ->Code), copy and paste the following Code into the VBA Module, below the existing Code lines.



 
Private Sub Home_Click()
On Error Resume Next
WebObj.GoHome
End Sub

Private Sub Back_Click()
On Error Resume Next
WebObj.GoBack
End Sub

Private Sub Forward_Click()
On Error Resume Next
WebObj.GoForward
End Sub

Private Sub Refresh_Click()
On Error Resume Next
WebObj.Refresh
End Sub

Private Sub Stop_Click()
On Error Resume Next
WebObj.Stop
End Sub



The On Error Resume Next Statement prevents the Subroutines running into Error, when there are no Web Pages to Navigate to.


To test these Buttons you must click on few links on the displayed Web Page to open other Pages from the same Website and then use these Buttons to navigate between those opened pages.


The Home Button will open the Default Home page you set in the Internet Explorer's Tools - -> Internet Options… Home Page - -> Address Control, not the default Value you set in the Combo Box.



StumbleUpon Toolbar



Filter Function Output in ListBox
Dynamic List Box Contents
Office Assistant and MsgBox Menus-3
Office Assistant and MsgBox Menus-2
Office Assistant and MsgBox Menus

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

 

©2009 Programming & Security | Template Blue by TNB

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii sonasol halfbakedtaters make-it-plain amatha lisboaohyeah lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir ojosmasabiertos ceilasantos