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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine if Form is open...

Status
Not open for further replies.

clapag22

Programmer
Mar 9, 2001
239
US
I have a main form called "Update Order". On this form there are several command buttons which open maintenance forms (vendor, carrier, purchaser, etc). By clicking on one of these buttons, the appropriate subform opens and you can add new information. In order to get this new information into the combo boxes on the main form, I have this code in the close event of the maintenance forms:

DoCmd.SelectObject acForm, "Update Order", 0
DoCmd.GoToControl "VendorID"
DoCmd.Requery "VendorID"

And this works great.

My problem is, these maintenance forms can also be opened from the main menu. When I open them from there and then try and close them it obviously blows up because the "Update Order" form is not currently open. So I know I need some sort of "If" statement to only run the the three lines of code above if the "Update Order" form is also open.

I tried:

***
if forms![update order].IsVisible then

DoCmd.SelectObject acForm, "Update Order", 0
DoCmd.GoToControl "VendorID"
DoCmd.Requery "VendorID"

end if
***

but that didn't do it. I'm sure this is fairly straightforward command as it would seem to be commonplace (because the only other option I can see is maintaining two forms that are exactly the same except for the close event code).

Thanks for any help!

Craig
 
clapag22:

All of this code goes in the same module.

Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.

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

'**********That piece of the code goes unedited*************

'Your statement to determine whether or not the form is open reads as follow

If IsLoaded(&quot;Update Order&quot;) = True Then
DoCmd.SelectObject acForm, &quot;Update Order&quot;, 0
DoCmd.GoToControl &quot;VendorID&quot;
DoCmd.Requery &quot;VendorID
End If


Hopes this helps you
 
Thanks!

I tried it out and now I am getting:


------------------
Compile Error:

Expected variable or procedure, not module.
------------------

Oh well.

Any clues?
 
i think you may get that error if you also call the module isLoaded. Try calling the module something different to the name of the function. Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top