Check to see if form is open

Dave_cha

Registered User.
Local time
Today, 22:44
Joined
Nov 11, 2002
Messages
119
I have two forms (FRM1 & FRM2) with list boxes. When either list box is double clicked they open a third form(FRM3).
When I close FRM3, I want to requery FRM1 or FRM2 depending on which is open. However, the requery request for the form which is closed throws up an error.

I've tried using;
"If [Forms]![FRMx].visible=true then [FRM].requery" but that's not the solution.

Does anyone know how I can use an if statment to check if the form is open before requesting a requery?

Thanks, Dave
 
Put this in a module:

Code:
Public Function IsFormOpen(strFormName As String) As Boolean
    IsFormOpen = (SysCmd(acSysCmdGetObjectState, acForm, strFormName) = acObjStateOpen)
End Function

Then, as you are using it:

Code:
If IsFormOpen("frmMyForm") Then Forms("frmMyForm").Requery
 
In the OnActivate event of both forms put Me.Requery or Me.SomeControl.Requery
 
Thanks for the help guys.

The IsFormOpen function works a treat.

Rich, I had already tried the OnActivate option but it wouldn't work. Not sure what I was doing wrong as I had it setup as you suggested. Focus went straight to the first control button but the form didn't requery?

Cheers,

Dave
 

Users who are viewing this thread

Back
Top Bottom