One VERY handy function is sensing if a fom is open. This is very handy, for example, if you want to program your forms to open up (or close down) any other forms when they are closed. For instance, I typically have a "browse_form" which shows all the records from a table in horizontal, columnar format, and then a regular form which shows all the fields from one record at a time. Opeing this "regular" form HIDES the "browse form" without completely closing it down. When this "regular" form is closed, I want the "browse_form" to re-open. However, if this "browse_form" is NOT open in the background, I don't want it opening. The key to doing this is the point of this page--how to sense if a form is open.
To do this, create a module under the "modules" tab, with the following code:
Function IsLoaded(ByVal strFormName As String) As Boolean ' Returns True if the specified form is open in Form view or Datasheet view. ' Derived from Microsoft's Northwind Database Const conObjStateClosed = 0 Const conDesignView = 0 If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then If Forms(strFormName).CurrentView <> conDesignView Then IsLoaded = True End If End If End Function |
This would go under the Option Compare Database/Option Explicit statement. Then name this module something like "utility_functions," but do NOT name it "isloaded."
Then, the code which would be used in the actual command button, whatever to execute this code and sense if the form is open would look like this:
If IsLoaded("purch_req_browse_form") Then |