HOW TO: Start Another Application from a Text Box on a Form (325234)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q325234
For a Microsoft Access 2000 version of this article, see 209170.

Moderate: Requires basic macro, coding, and interoperability skills.

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

IN THIS TASK

SUMMARY

This article describes how you can start another application from a text box on a Microsoft Access form. back to the top

Steps to Start Another Application from a Text Box in Microsoft Access

You can start another application from a text box that is on a form by using the Shell Command in Microsoft Visual Basic for Applications (VBA). The following example demonstrates how to start an application and how to load the file whose file name is typed in the text box. This example starts Microsoft Word and then loads the file from the My Documents folder.

Note This example assumes the default installation of Word. Make sure that the command-line command below points to the correct drive and to the folder where Winword.exe is located on your computer. The test document that is used must be present in the My Documents folder.
  1. Create a new form with two text boxes that are named txtAppPath and txtFilePath.
  2. Put a command button on the form that has the following properties:
    Name: cmdOpenApp
    Caption: Open Application
    					
  3. Put the following code on the OnClick event of the button:
    Private Sub cmdOpenApp_Click()
        Dim str As String
        str = Chr(34) & Me!txtAppPath & Chr(34) & " " & Chr(34)& Me!txtFilePath & Chr(34)    
        Call Shell(str, 1)
    End Sub
    					
  4. Save the changes to the form.
  5. In the txtAppPath text box, type the complete path to the Microsoft Word 2002 executable as follows:

    c:\program files\microsoft office 2000\office10\winword.exe

  6. In the txtFilePath text box, type the name of the Word document that you want to open.

    For example, if there is a file that is named Test.doc that is in your My Documents folder, then you can type Test.doc in the textbox.
  7. Open the document in Word 2002.
back to the top

Modification Type:MinorLast Reviewed:4/6/2006
Keywords:kbHOWTOmaster KB325234 kbAudDeveloper