ACC2000: How to Start Another Application from a Data Access Page

ID: Q234303


The information in this article applies to:

Advanced: Requires expert coding, interoperability, and multiuser skills.

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


SUMMARY

This article shows you how to start another application from a Microsoft Access data access page.


MORE INFORMATION

The following example demonstrates how to start an application and to load a file whose name you type in a text box. This example starts Microsoft Word for Windows and loads a document that you specify.

  1. Start Microsoft Access.


  2. In the Database window, click Pages under Objects, and then click New.


  3. In the New Data Access Page box, click Design View, and then click OK.


  4. Place a text box in the Section: Unbound section of the page.


  5. Set the following properties for the text box:


  6. 
       Id: txtApp
       Left: 2in
       Top: 0.5in
       Width: 1in 
  7. Set the following properties for the text box label:


  8. 
       FontWeight: bold
       InnerText: Application Name:
       Left: 0in
       TextAlign: right
       Top: 0.5in
       Width: 2in 
  9. Place another text box in the Section: Unbound section of the page.


  10. Set the following properties for this text box:


  11. 
       Id: txtDoc
       Left: 2in
       Top: 0.75in
       Width: 4in 
  12. Set the following properties for the text box label:


  13. 
       FontWeight: bold
       InnerText: Path and File Name:
       Left: 0in
       TextAlign: right
       Top: 0.75in
       Width: 2in 
  14. Place a command button in the Section: Unbound section of the page.


  15. Set the following properties for the command button:


  16. 
       Id: cmdOpenApp
       FontWeight: bold
       InnerText: Open App
       Left: 2.5in
       Top: 1in 
  17. Place another command button in the Section: Unbound section of the page.


  18. Set the following properties for the command button:


  19. 
       Id: cmdCloseApp
       FontWeight: bold
       InnerText: Close App
       Left: 2.5in
       Top: 1.25in 
  20. On the File menu, click Save, and save the page as LaunchApp.htm. Make a note of the folder where this file is saved. You will need this information later in these steps.


  21. On the Tools menu, point to Macro, and then click Microsoft Script Editor.


  22. On the HTML menu, point to Script Block, and then click Client. Insert the following script:


  23. 
    <SCRIPT language=vbscript>
    <!--
       Option Explicit
       Dim Obj
    -->
    </SCRIPT> 
  24. Using the Script Outline, insert the following script for the OnClick event of the cmdOpenApp command button:


  25. 
    <SCRIPT event=onclick for=cmdOpenApp language=vbscript>
    <!--
       Dim strApp, strDoc
       Dim intPosition
    
       strApp = document.all.item("txtApp").Value
       strDoc = document.all.item("txtDoc").Value
    
       If Not IsNull(strApp) And strApp <> "" Then
          Set Obj = CreateObject(strApp & ".Application")
          Obj.Application.Visible = True
       Else
          MsgBox "Must enter an Application Name."
          Exit Sub
       End If
    	
       If Not IsNull(strDoc) and strDoc <> "" Then
          Select Case UCase(StrApp)
             Case "ACCESS"
                Obj.OpenCurrentDatabase strDoc
             Case "EXCEL"
                Obj.Workbooks.Open strDoc
             Case "WORD"
                Obj.Documents.Open strDoc
             Case Else
                MsgBox "Application Unknown."
                Exit Sub
          End Select
       End If
    -->
    </SCRIPT> 
  26. Using the Script Outline, insert the following script for the OnClick event of the cmdCloseApp command button:


  27. 
    <SCRIPT event=onclick for=cmdCloseApp language=vbscript>
    <!--
       Obj.Application.Quit
       Set Obj = Nothing
    -->
    </SCRIPT> 
  28. Close the Microsoft Script Editor and Microsoft Access, and when prompted, click Yes to save changes.


  29. Start Microsoft Internet Explorer 5.


  30. On the File menu, click Open.


  31. Click Browse and locate the folder where the LaunchApp.htm file is stored.


  32. Click LaunchApp.htm and click Open.


  33. Click OK and type Word in the Application Name text box.


  34. In the next text box, type a path and file name to some Word document, such as C:\Windows\Script.doc.


  35. Click Open App. Note that Word starts and opens the document that you specified.


  36. Click Close App to quit Word.


Additional query words:


Keywords          : kbdta AccDAP DAPScriptHowTo 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: July 26, 1999