"sub terminate" is executed. How can I disable this?

51 Views Asked by At

The output of the MS Word report is set in "sub terminate". When terminating - exiting the form with the "X" button, a "sub terminate" is also executed. How can I disable this?

I'm working on an old case and I don't know why the output is written in sub terminate?

1

There are 1 best solutions below

1
Tode On

Simple answer: You can't.

There are code parts that are ALWAYS executed. For any LotusScript-Container this is "Sub Initialize" when it is loaded and "Sub Terminate" when it is unloaded.

For e.g. a form there are events like "QueryOpen", "PostOpen", "QuerySave", "PostSave"... etc. as well: You can't stop these events from executing as well.

Now if your code is in Sub Terminate but you do not want to execute it when the window closing "X" button is pressed, then you need to set a flag somewhere. And if this flag is missing: Don't execute.

You could choose global variables, document item values or environment variables to determine if the code should be executed:

I'll show one example with a global variable:

In (Declarations) put:

Dim executeTerminate as Boolean

In your Terminate you wrap your existing code:

If executeTerminate Then
  '- your code
End If

Or you exit (if you do not like the indentation of the additional if:

If executeTerminate = False Then Exit Sub

Now whenever "x" is clicked nothing happens.

If you have a button that should trigger the code, then use this inside of the button:

executeTerminate = True

That should do the trick. As said you could also use document items or environment variables to do the trick:

'- in button
'- With item:
Call doc.Replaceitemvalue( "ExecuteTerminate" , "1" )
'- With Environment
Call session.SetEnvironmentVar( "ExecuteTerminate" , "1" )

'- in Terminate
'- item:
If doc.GetitemValue( "ExecuteTerminate" )(0) = "1" Then
  '- don't forget to reset
  Call doc.Replaceitemvalue( "ExecuteTerminate" , "" )
'- Environment:
executeTerminate = session.GetEnvironmentString( "ExecuteTerminate" )
'- don't forget to reset
Call session.SetEnvironmentVar( "ExecuteTerminate" , "" )
If executeTerminate = "1" Then