Closing a form from another form (1 Viewer)

velcrowe

Registered User.
Local time
Today, 05:31
Joined
Apr 26, 2006
Messages
86
I have a search field on my form A that opens another form B to show the list of records I'm looking for in the database. I can click on a list item in form B and it will open the record in form A. Once an item is clicked in form B it hides in the background of form A so I can refer back to the search. When I need a new search I have to close form B and run the search again in form A. Is there a way (with code) before the search begins to see if form B is open and if so close it and then run the search. If the form isn't open, then resume the search as normal. I just don't want to close form B manually to begin a new search. Thank you u
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:31
Joined
Aug 30, 2003
Messages
36,132
You can use DoCmd.Close to close the form, and search on IsLoaded to test whether it's already open.
 

velcrowe

Registered User.
Local time
Today, 05:31
Joined
Apr 26, 2006
Messages
86
Would the code look something like this:

If forms!FormB.isloaded then docmd.close acform "formB"
Else...

Thank you
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:31
Joined
Aug 30, 2003
Messages
36,132
Presuming you fix the syntax problems, yes (see VBA Help on both). I'm not personally a fan of mixing block and one line formats, so I'd do:

Code:
If Whatever Then
  DoCmd....
Else
  'other code
End If

Of course unless there's more to what you're doing, you don't need an Else.
 

Users who are viewing this thread

Top Bottom