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

Determine if form is open 1

Status
Not open for further replies.

sirkenj

Technical User
Apr 30, 2002
52
US
Hello all, I'm a newbie to VBA, and am slowly picking it up, but I need some help on this one! The basic situation is this: I have a form (form1) which contains a combo box that is Limited to List. OnNotInList, a Sub will ask the user if they wish to add a new value. If yes, a form opens (form2) and goes to a new record for them to add the information. (there are several fields, so using a second form is the easiest way for me to accomplish this) Once data is input on form2, on close, I need to requery the combo box, which is done through another sub attached to the OnClose event of form2.
The problem is that form2 is also used to just view the data it contains, separate from being opened by form1. So I need to be able to determine if form1 is opened, if so, requery my combo box, if not, just close the form. Here's what I'm working with so far, though I'm certain this isn't the best way to tackle this one:

Private Sub Form_Close()
'Can I nest this function in a sub? If not, what is the easiest way to determine if the form is opened in this sub?
Function IsLoaded(ByVal strFormName As String) As Boolean
'Returns True if the specified form is open in form view or datasheet view

Const OBJ_STATE_CLOSED = 0
Const DESIGN_VIEW = 0

If SysCmd(acSysCmdGetObjectState, acForm, Forms![frm01-01Master]![frm02-02CasesSUB]) <> OBJ_STATE_CLOSED Then
If Forms([frm01-01Master]![frm02-02CasesSUB]).CurrentView <> DESIGN_VIEW Then
IsLoaded = True
End If
End If
End Function

Forms![frm01-01Master]![frm01-02CasesSUB].Form!AssFacilityCode.Requery
Forms![frm01-01Master]![frm01-02CasesSUB].Form!TreatFacilityCode.Requery
End Function
 
This code works for me. First put this code in a standard module so it can work in any form:

Public Function IsLoaded(ByVal strFormName As String) As Boolean
'Checks to see if a particular form is loaded
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


Then add this code to your second form:
If CurrentProject.AllForms(&quot;NameOfMyFile&quot;).IsLoaded Then
' code to accomplish task

End If
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top