As with the UserControl object, you can create public properties for UserDocument objects. When you create a public property, you expose the property so other applications can set or get its value. In the ActXDoc project, you'll create a single property that can be accessed by either another ActiveX document or by a form. In this procedure, you will also add a code module to the project to contain a single global module.
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 property to FirstDoc
' Object variable for FirstDoc
Public gFirstDoc As FirstDoc
This global variable will contain the object reference that links the FirstDoc and SecndDoc ActiveX documents.
Text1 property | Value |
Name | txtFirstDoc |
Text | (nothing) |
Public Property Get strDocProp() As String
' Note: in the line above, change the return type
' of the property from "As Variant" to
' "As String."
strDocProp = txtFirstDoc.Text
End Property
Public Property Let strDocProp(ByVal _
NewStrDocProp As String)
' Note: in the line above, change the argument
' type from Variant to String.
txtFirstDoc.Text = NewStrDocProp
End Property
The code above exposes the strDocProp property as a public property of the FirstDoc ActiveX document. In other words, it delegates to the Text property of the TextBox control the work of displaying and storing the string. Now that the property is public, you can pass its value to the SecndDoc object. You will do this by modifying the code for the Go Next command button.
Private Sub cmdGoNext_Click()
' Note: the following path may not correspond to
' the actual path to the SecndDoc.vbd file on
' your machine.
Set gFirstDoc = Me ' <-- Add this line.
HyperLink.NavigateTo _
App.Path & "\SecndDoc.vbd"
End Sub
Private Sub UserDocument_Show()
If Not gFirstDoc Is Nothing Then
lblCaption.Caption = gFirstDoc.strDocProp
Set gFirstDoc = Nothing
End If
End Sub
In the code in step 11, you set the global object variable to the FirstDoc document. The code in step 13 tests to see if the global variable is set to an object. If it is, then the public properties of the ActiveX document are available, and the caption of the label is set to the strDocProp property from the FirstDoc document. Immediately after setting the Caption property, the global variable is destroyed (set to Nothing).
Note "It is bad practice to allow the global variable to retain a reference to the FirstDoc UserDocument; the reasons for this are covered in the "Building ActiveX Documents."
This topic is part of a series that walks you through creating a sample ActiveX document.
To | See |
Go to the next step | Saving Properties to the PropertyBag |
Start from the beginning | Creating an ActiveX Document |