I was working on a database that linked a lot of data to other data, employing many join tables. It is a database about maintaining a library of video and audio recordings of art events. The idea is to allow researchers explore and move through Artists, Events, Media Assets, Groups and Programs easily. As a result, I decided to build it so that it opens window after window. The user can jump from an Artist to an Event, or Group. After a while the screen can get cluttered, so I wanted an easy way to clean up the screen and get the user back to basics.
A Google search brought me to this thread on FMForums on how to get the count of open windows in FileMaker. Here is a demo file of how I wrote the script in my database.
Demo File – Open a Bunch of Windows

1) Enter the number of windows you want to mess up your screen with.
2) Click the “Open a Bunch of Windows” button.
Too many windows

The screen will be populated with windows.
Click the “Clean Up Windows” button to return to a single window.

The key to the script is:
ValueCount(WindowNames(Get(FileName))
This function gives you a count of open windows. From there, I wrapped it in a loop that Closes all Windows, but that is set to halt if there is only a single window left on screen. If you have only one window to start with, the script halts before it gets going.
Related Articles:
Windows Management Part II: How to stop the user from accidentally closing the last window in a FileMaker database
Changing Window Names based on User Input
Yes, but what good does the count of window names do if some are hidden? Your count may indicate that one window is still open, but the user sees only an empty screen…
True. I didn’t really think of this because usually someone quits from the last window and they are looking at it. It is hard to click a close or exit button from a hidden window. Still if you anticipate it being a problem, you could add some kind of conditional test in the On Close script. Something like:
If [Get(WindowVisible)=0]
Adjust Window [Resize to Fit]
End If
The other issue of course is that this will end the user up on a random screen. What I do – which may not be very elegant – is this:
1) Close all windows but 1 (if you close all of them then the file closes…)
2) Rename that window with at temporary unique title not used elsewhere (e.g. XYZ)
3) Create a new window with desired size, name attributes etc.
4) Close the temporary window
That does the job!