Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBA Code needed:  Is Form Open?

Posted on 2001-07-24
6
Medium Priority
?
347 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 40 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 31

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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