Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA Code needed:  Is Form Open?

Posted on 2001-07-24
6
Medium Priority
?
352 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
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's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

886 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