Solved

VBA Code needed:  Is Form Open?

Posted on 2001-07-24
6
316 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:knowlton
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 5

Author Comment

by: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:knowlton
ID: 6317488
If you ever find that autogenerated code (what situation) I would be interested!

Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

828 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