ACC2002: How to Determine If a Page Is Open in Access or Internet Explorer (304235)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q304235
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

This article describes how to use the HTML document object model to determine if a data access page is open in Microsoft Access or Microsoft Internet Explorer.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Sample Code

  1. Start Microsoft Access.
  2. On the Help menu, point to Sample Databases, and then click Northwind Sample Database. Close the Switchboard form when it appears.
  3. In the Database window, click Pages under Objects, and then click New.
  4. In the New Data Access Page dialog box, click AutoPage: Columnar. In the Choose the table or query where the object's data comes from list, click Customers, and then click OK.
  5. Save the new page as Customers.htm to a local path on your computer.
  6. On the View menu, click Design View.
  7. If the Toolbox is not displayed, click Toolbox on the View menu.
  8. Add a command button to the page, and then set the following properties for the command button:
       ID: cmdOpenWhere
       InnerText: Open Where
    					
  9. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  10. In the Client Objects & Events list, click cmdOpenWhere, and then click onclick in the Events list.
  11. Type the following code between the <SCRIPT> tags:
    Dim strLocation
    
    ' Use window.location.protocol to get the protocol for the current page.
    strLocation = window.location.protocol
    
    Select Case strLocation
        Case "http:", "https:", "ftp:"
            MsgBox "This page is open in Internet Explorer using an Internet protocol."
        Case "file:"
            MsgBox "This page is open in Internet Explorer using a file system path."
        Case "accdp:"
            MsgBox "This page is open in Microsoft Access."
        Case Else
    	MsgBox "Cannot determine protocol."
    End Select
    					
  12. On the File menu, click Exit. Save your changes when you are prompted to do so.
  13. Test the page by using any of the following methods:
    • On the View menu, click Page View. Click the command button to test the page.
    • Open the folder where the page is saved, and double-click the page to open it. Click the command button to test the page.
    • If you have a Web server, copy the page from your local computer to the Web server, and open the page by using the Hypertext Transfer Protocol (http) address for the page. Click the command button to test the page.

REFERENCES

For more information about the protocol property and predefined protocols, click Microsoft Script Editor Help on the Help menu, type protocol property in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbhowto KB304235