Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if a form is open

Status
Not open for further replies.

Felgar

Programmer
May 17, 2001
17
CA
Hi, I have a form (CandidateSearch Subform) that uses a query as it's datasource. The query has paramaters that come from a second form (CandidateSearch), and these paramaters are used to decide what records to include in the query and therefore to show in the results. The names are misleading, CandidateSearch Subform is not a Subform of CandidateSearch. It used to be, before I wanted my search paramaters on a separate form.

I am trying to implement my Search form so that the user can enter the parameters, click on "Do Search" button, and then have either: 1) The results form open and show the results, if it is not open. Or 2) The results form Requery it's data to meet the new criteria, if it is already open.

The code I used to do this before is shown below. Note, that I simply try to reference the form, and then OnError I know that the form reference failed, so I then open the form. This is obviously not ideal. But for a while, it worked.

Private Sub DoCandidateSearch_Click()
On Error GoTo TestError
If (IsNull(Forms![CandidateSearch Subform]) = False) Then
Forms![CandidateSearch Subform].Requery
End If
Test_Exit:
Exit Sub
TestError:
DoCmd.OpenForm "CandidateSearch Subform"
Resume Test_Exit
End Sub

But now I want to change some properties of the results form based on the user's criteria also. Ie: Change the color of the fields that the user included as a parameter. So I really need a better way to determine if the form is already open. If not, I have to put the color changing code in both the error handler and the main subroutine.

 
if syscmd(acsyscmdgetobjectstate,acform,"formname") = 0 then
do this
end if
 
there is a function with one of the sample databases called 'isloaded'. Every db I create I include this function. Once u have this function in a module you simply call it by:

if isLoaded("formName") then
do something
else
do something else
end if

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top