Approach User Support homepage Approach User Support
Answers to Frequently Asked Questions about Lotus Approach
Examples LotusScripts
Example databases
Links to other Lotus Approach support services

[Return to contents]

Example LotusScript: Activating a macro in another APR

Last updated: before December, 1998

Jerry Sikes wrote:
<blockquote>
Here is the script method I use to activate a macro in another APR. I have a global sub called OpenMyDocs in the first APR(calling or source APR). It can be called by a click event or run from a macro. This script checks to see if the target application is already open. If true it uses the activate method and if false it use the opendocument method. This is followed by a RunProcedure method. This runprocedure method is how you start a global script in the second APR. The called script
can launch a macro with the RunApproachMacro method. The RunProcedure arguments allows a parameter to be passed.

This example passes a do nothing parameter. The called or target APR must have a global sub, such as the example OutsideSub shown. Here I accept the do nothing parameter and simply launch the desired macro. One note, if your target application's name has multiple words with spaces, you must be carefull with the activate method syntax. The OpenDocument method uses string quotes to enclosed the apr name. The activate method does not. For example, If I had previously opened the "Inventory Control Program.APR" and switched backed to another APR, the OpenMyDoc sub
would find this already open and branch into true section of the MyOpen = "True" if statement. The correct syntax should be:

     CurrentApplication.Inventory~ Control~ Program.activate

The trick is to use a tilde(~) before each space.
</blockquote>

'Submitted by Jerry Sikes
Sub OpenMyDocs
        Dim MyDoc As String
        Dim NumDocs As Integer
        Dim Docs As Variant
        Dim MyOpen As String
        Dim fname As String
        If(CurrentApplication.Documents.IsEmpty=False) Then
                NumDocs = CurrentApplication.Documents.count
                For i = 0 To NumDocs-1
                        If CurrentApplication.Documents(i).Name="INVYTRANS" Then
                                MyOpen="True"
                        End If
                Next
        End If
        If MyOpen ="True" Then
                CurrentApplication.INVYTRANS.activate
        Else
                Set CurrentDocument=currentapplication.OpenDocument("INVYTRANS.apr","e:\standard\") 
        End If
        Call currentapplication.RunProcedure("OutsideSub","Hello")
End Sub

Sub OutsideSub(MyArg As String)
        RunApproachMacro("Update Records Macro")
End Sub

[Return to contents]

© Copyright, JohnBrown, Trademarks, Disclaimer, Acknowledgements.