Solved

know if an Access form is loaded

Posted on 2011-03-22
5
283 Views
Last Modified: 2012-05-11
I have always seen this code for detecting if a form is loaded:

    Dim blMyFormLoaded As Boolean
    Set dbs = Application.CurrentProject    
    For Each obj In dbs.AllForms
        If obj.IsLoaded = True And obj.Name = "[put_here_the_desired_form-name]" Then
            blMyFormLoaded = True
          Exit For
        End If
    Next obj

But I've come up with this Idea:

    Dim blMyFormLoaded As Boolean
    Dim f As Form
    For Each f In Application.Forms
      If f.Name = "[put_here_the_desired_form-name]" And f.CurrentView<>0 then
           blMyFormLoaded = True
             Exit For
      End If
    Next

Doesn't it seem that the second is better? The Forms collection contains only open forms, while the AllForms collection contains all of them. Consider the fact that my app has got 666 forms.
0
Comment
Question by:NNOAM1
  • 2
  • 2
5 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 35188012
Well, try and click a stopwatch ...

Under normal use most apps have zero forms open in designview.

/gustav
0
 

Author Comment

by:NNOAM1
ID: 35188513
OK, let's remove the: "And f.CurrentView<>0". Are both methods OK with you?
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 35188533
Yes, but I think I would do:
    Dim blMyFormLoaded As Boolean
    Set dbs = Application.CurrentProject    
    For Each obj In dbs.AllForms
      If obj.IsLoaded = True Then
        If obj.Name = "[put_here_the_desired_form-name]" Then
          blMyFormLoaded = True
          Exit For
        End If
      End If
    Next obj


    Dim blMyFormLoaded As Boolean
    Dim f As Form
    For Each f In Application.Forms
      If f.Name = "[put_here_the_desired_form-name]" Then
        If f.CurrentView <> 0 Then
          blMyFormLoaded = True
          Exit For
        End If
      End If
    Next

Open in new window


/gustav
0
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
ID: 35188616
If you are testing for a specific form then Isloaded is easier and direct and doesn't require any loops.

 if currentproject.allforms("form2").isloaded then ....
0
 

Author Closing Comment

by:NNOAM1
ID: 35190201
That's the thing I was looking for! Thank you.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

744 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

15 Experts available now in Live!

Get 1:1 Help Now