Solved

know if an Access form is loaded

Posted on 2011-03-22
5
321 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
[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
  • 2
  • 2
5 Comments
 
LVL 50

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 50

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

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
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 different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

688 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