Solved

know if an Access form is loaded

Posted on 2011-03-22
5
317 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

737 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