Solved

VBA Code needed:  Is Form Open?

Posted on 2001-07-24
6
327 Views
Last Modified: 2008-02-26
In Form1 I am opening Form2.

After Form2 is open, in Form1 I want to click a button that will tell me if Form2 is open.

I need a function that will return a boolean, true (open) or false (form is not open).

Function IsFormOpen(FormName As String) As Boolean

  'Is the form open???

End Function
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Accepted Solution

by:
BozzoCage earned 10 total points
ID: 6314557
Function IsLoaded(ByVal strFormName As String) As Integer
 ' 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
0
 
LVL 30

Expert Comment

by:hnasr
ID: 6315422
Good answer. Remeber the help and sample databases that come with Access.
0
 
LVL 12

Expert Comment

by:Paurths
ID: 6315673
ah well,

http://www.mvps.org/access/forms/frm0002.htm

Function fIsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
        If Forms(strFormName).CurrentView <> 0 Then
            fIsLoaded = True
        End If
    End If
End Function
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6315711
My solution was:

Function IsFormOpen(FormName as String) as Boolean

  Dim temp_form as Form
  Dim is_open

  is_open = false  'init to FALSE
  For Each temp_form in Forms
    if temp_form.Name = FormName then
      is_open = true
    End If
  Next

  IsFormOpen = is_open
End Function

Perhaps not the best?
0
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6316189
Interesting... I use such code in VB, but for some reason I though it wouldn't work in VBA (Access). I can't remember... perhaps Access 97 didn't supported that.

If you'r not aware of all uses of Forms collection:
MsgBox Forms("frmProducts").Caption
You just need to take care if form is open before such sentences (or use "On Error Resume Next").

Btw... code I pasted as a solution was autogenerated/supplied by Access (can't recall in what situation).

Regards,
  BozzoCage
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6317488
If you ever find that autogenerated code (what situation) I would be interested!

Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question