Solved

VBA Code needed:  Is Form Open?

Posted on 2001-07-24
6
286 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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now