X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Vba To Test If Any Form Is Open, Not Just A Specific One, Access 2007    
post Apr 2 2020, 05:57 PM

Posts: 41
Joined: 4-May 05

Hi! I apologize if this is really simple, I'm just not that savvy. I have searched for VBA code that would tell me if any form was open in form view(not just a specific form) and have been thwarted. I have seen examples such as If IsOpen ("frmNameofForm") Then... but does anyone know how to see if ANY form is open without specifying a name of the form?

Again, sorry if this is obvious or simple, thank you in advance!

Go to the top of the page
post Apr 2 2020, 06:03 PM

Posts: 1,385
Joined: 26-December 12
From: Berkshire Mtns.

You'll need to iterate through the forms collection and test for .isloaded.

    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject
    ' Search for open AccessObject objects in AllForms collection.
    For Each obj In dbs.AllForms
        If obj.IsLoaded = True Then
            ' Print name of obj.
            Debug.Print obj.Name
        End If
    Next obj

This post has been edited by moke123: Apr 2 2020, 06:10 PM
Go to the top of the page
post Apr 2 2020, 06:10 PM

Posts: 2,996
Joined: 4-February 07
From: USA, Florida, Delray Beach

Removed Code, posted simultaneously with moke123.
This post has been edited by ADezii: Apr 2 2020, 06:12 PM
Go to the top of the page
post Apr 2 2020, 06:16 PM

Posts: 41
Joined: 4-May 05

Thank you so much, not only for the assistance but for responding so quickly! I truly do appreciate it!!

Go to the top of the page
post Apr 2 2020, 06:26 PM

UA Moderator
Posts: 78,125
Joined: 19-June 07
From: SunnySandyEggo

Hi Bill. Just curious, does it matter if the form was open in design view?

Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
post Apr 2 2020, 06:29 PM

Posts: 41
Joined: 4-May 05

Hi DBGuy,

Yes, I'd like to just check for any forms open in Form view... does the code check no matter what view is active?
Go to the top of the page
post Apr 3 2020, 03:14 AM

Retired Moderator
Posts: 19,777
Joined: 14-July 05
From: Sydney NSW Australia

Are you saying that you are only interested in Forms that are opened in FormView (Single Form or Continuous Form) and NOT the DesignView or DatasheetView?

If so, try:
Dim objFrm as Access.Form

For Each objFrm In Forms
  If objFrm.CurrentView = acCurrentView.acCurViewFormBrowse Then
    Debug.Print objFrm.Name
  End If
Next objFrm
Go to the top of the page
post Apr 3 2020, 04:50 AM

UtterAccess VIP
Posts: 2,245
Joined: 21-February 07
From: Copenhagen

A form cannot be "thwarted". What do you mean its state should be?

To check that any form is open - no matter its current view state:

SomeFormIsOpen = CBool(Forms.Count)

Microsoft Office 365 (Access) MVP 2017 ->
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    31st May 2020 - 12:32 PM