?
Solved

know if an Access form is loaded

Posted on 2011-03-22
5
Medium Priority
?
324 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 51

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 51

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 1000 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

752 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