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

Is there a way to check and see if a form is open?

Status
Not open for further replies.

b31luv

Technical User
Feb 21, 2002
171
US
I have this piece of code written

Private Sub Form_Open(Cancel As Integer) 'When Submittal Info Form is opened, bring over info for ProjectName and Number from "Form - Project Info"

With Forms![Form - Project Info]
Me.Text16 = Forms![Form - Project Info]!Text15
Me.Text18 = Forms![Form - Project Info]!Text17
End With

stDocName1 = "Form - Project Info"
DoCmd.Close acForm, stDocName1

End Sub

The problem I have now is that [Form - Project Info] has to be open now in order to open [Form - Submittal Info]. Can I check to see if the Form or Object is open/closed, true/false, a -1/0, or something? If so, I'm thinking an If Statement.

If [Form - Project Info] = Open Then

With Forms![Form - Project Info]
Me.Text16 = Forms![Form - Project Info]!Text15
Me.Text18 = Forms![Form - Project Info]!Text17
End With

Else

DoCmd.OpenForm "Form - Submittal Info", acNormal

Any takers. Can it be done? [elephant2]
 
Hi

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

from Northwind.mdb Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Ken,

Before I got your response I added a line in my error statement which opens the form in question and then moves on thru the rest of the code, is that ok or is it a bad way of writing the code?
 
Here's another option, somewhat limited. It won't tell you whether the form is opened in Design or Run view. If the form is new and open and has not yet been saved it will not show up in the All Forms collection. Anyway, here it is.

Dim bolOpen as Boolean

bolOpen = CurrentProject.AllForms(&quot;Form - Project Info&quot;).IsLoaded

if (bolOpen) then
msgbox &quot;opened&quot;
else
msgbox &quot;closed&quot;
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top