Visual Basic Concepts

Adding a Second ActiveX Document to the ActXDoc Project

See Also

Having one ActiveX document in a project is equivalent to having a single form in a project — somewhat limiting. To increase your capabilities, add a second ActiveX document to the ActXDoc project.

Unlike standard Visual Basic forms, you cannot use the Show method to show ActiveX documents. This is because the container application (in this case, Internet Explorer) determines when to show or hide the ActiveX document. Instead, you must navigate from one ActiveX document to another. To navigate between the two ActiveX documents, use the HyperLink object and its NavigateTo method.

Note   This topic is part of a series that walks you through creating a sample ActiveX document. It begins with the topic Creating an ActiveX Document.

To add a second ActiveX document to the ActXDoc project

  1. Before adding a second ActiveX document to the project, add a CommandButton control to the FirstDoc designer. On the Toolbox, double-click the CommandButton icon to add a CommandButton control to the FirstDoc designer.

  2. Set the appropriate properties for the control using the following table:
    Command1 property Value
    Name cmdGoNext
    Caption Go Next

  3. Position the control on the FirstDoc designer as shown.

  4. Double-click the Go Next button and add the following code to the button's Click event:
    Private Sub cmdGoNext_Click()
       ' Note: the following path may not correspond to 
       ' the actual path to the SecndDoc.vbd file on 
       ' your machine.
       HyperLink.NavigateTo _
       App.Path & "\SecndDoc.vbd"
    End Sub
    

    Note   The App.Path code only works if you keep ActXDoc project in the same directory where you installed the Visual Basic application. If you save the project to another directory, replace App.Path & "\SecndDoc.vbd" with the hard-coded path of the SecndDoc.vbd file.

    When you are running the project, Visual Basic always creates a temporary .vbd file for each ActiveX document in your project, and the .vbd files will always be found in the same directory where Visual Basic has been installed. However, if you are compiling an .exe or .dll, Visual Basic will create the .vbd file in the same directory as the .exe or .dll file.

  5. This next step will insert a second ActiveX document into the project. On the Project menu, click Add UserDocument to open the Add User Document dialog box.

  6. Double-click the User Document icon to add an ActiveX document to the project.

  7. On the Properties window, double-click Name and change the name of the new UserDocument object to SecndDoc. The caption should now read "ActXDoc - SecndDoc (UserDocument)."

  8. Add Label and CommandButton controls to the SecndDoc User document, and use the following tables to set their properties.
    Label1 property Value
    Name lblCaption
    Caption SecndDoc

    Command1 property Value
    Name cmdGoBack
    Caption Go Back

  9. Position the controls on the SecndDoc User document as shown:

  10. Add the following code to the Click event of the cmdGoBack button:
    Private Sub cmdGoBack_Click()
       UserDocument.HyperLink.GoBack
    End Sub
    

    The HyperLink object features the GoBack method, which will navigate back to the previous document in the browser.

  11. On the File menu, click Save Project to save the project files. Name them as shown in the following table. Visual Basic will provide the indicated extensions automatically.
    File File name Extension
    User document SecndDoc .dob

Running the Project

Now that you have added a second ActiveX document, you can run the project and navigate between the two.

  1. Run the project by pressing F5. Internet Explorer will be launched.

  2. In Internet Explorer, type the path of the FirstDoc.vbd file in the Address box.

Tip   If you previously opened the FirstDoc ActiveX document in Internet Explorer, click the arrow next to the Address box to see a list of recent URLs. The FirstDoc document should be available from the drop-down list.

  1. Click Go Next. You will now be on the SecndDoc document.

  2. On the SecndDoc document, click Go Back to return to the FirstDoc ActiveX document.

Step by Step

This topic is part of a series that walks you through creating a sample ActiveX document.

To See
Go to the next step Adding a Form to the ActXDoc Project
Start from the beginning Creating an ActiveX Document