KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to close a window from outside the context of a form's execution
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: May 9, 2025

In 4D, you may run into situations where you need to close a window from outside the context in which it was opened — for example, from a different method or even a separate process.

If you simply run the following code, it will not work:

CLOSE WINDOW($windowRef) // No effect

This happens because those windows are not external (i.e., they were not created in a way that returns a valid WindowRef). In this case, CLOSE WINDOW is simply not applicable.

To have full programmatic control over windows, you must call call Form:

CALL FORM($windowRef; Formula(CANCEL))