How to test whether a form is opened as hidden? (2 Viewers)

HalloweenWeed

Member
Local time
Yesterday, 22:59
Joined
Apr 8, 2020
Messages
222
Hi once again all. I have a split-database where I am using some db settings parameters and opening a hidden form to give other objects a settings source to make things change according to the settings without opening a vba recordset to do so. I'm trying to make it easier for future db admins after I leave my job, so simplifying the vba as much as possible without hamstringing the functionality.

So I'm using:
Code:
DoCmd.OpenForm stDocName, , , , , acHidden

But I need the ability of the user (next admin) to open the settings form and perform or inspect settings, and then restore it to hidden. But when I use this code:
Code:
If CurrentProject.AllForms(stDocName).IsLoaded Then
If CurrentProject.AllForms(stDocName).CurrentView = acCurViewFormBrowse Then
If CurrentProject.AllForms(stDocName).Visible Then
I get an error testing .Visible. Is there an alternative way to test whether the form is hidden? I've googled and searched, but nothing comes up. The results are about other issues with same keywords, but either not about vba, or not about testing the form object itself. Thank you.
 
If Forms(stDocName).Visible Then
Unlike the AllForms collection, the Forms collection is the set of open forms.
Note this only works for parent forms, not subforms.
 
If Forms(stDocName).Visible Then
Unlike the AllForms collection, the Forms collection is the set of open forms.
Note this only works for parent forms, not subforms.
Thank you Tom, that works great! I'm all set now.
 
To understand why this fails
Code:
If CurrentProject.AllForms(stDocName).Visible Then

The allforms collection returns a very different object then the forms collection.
Allforms returns an AccessObject which is a very simple object compared to a form returned from the forms collection. It does not have a Visible property
In Microsoft Access, the AccessObject type represents objects in the AllForms, AllReports, AllTables, and similar collections. Its properties are fairly limited because it’s a lightweight descriptor rather than the full object. The key properties of an AccessObject are:

Key Properties of​

  • Name (String)
    Returns the name of the object (e.g., "EmployeesForm"). [learn.microsoft.com]
  • Type (AcObjectType)
    Indicates the type of object it represents (e.g., acForm, acReport, acQuery). [learn.microsoft.com]
  • IsLoaded (Boolean)
    Indicates whether the object is currently open in Access. [learn.microsoft.com]
  • FullName (String)
    Provides the full system path of the object, including the .accdb or .mdb file location if stored externally. [learn.microsoft.com]
  • DateCreated (Date)
    The timestamp when the object was first created in the database. [learn.microsoft.com]
  • DateModified (Date)
    The timestamp of the last modification to the object. [learn.microsoft.com]
  • CurrentView (AcCurrentView)
    Shows the view state (like Design, Datasheet, or Form view) for form and report objects. [learn.microsoft.com]
  • IsWeb (Boolean)
    Indicates whether the object is a web-enabled form or report. [learn.microsoft.com]
  • Parent (AccessObjectContainer)
    The container to which this object belongs (e.g., the AllForms or AllReports collection). [learn.microsoft.com]
  • Properties (AccessObjectProperties)
    A collection representing both built-in and custom properties attached to the object. [learn.microsoft.com], [learn.microsoft.com]

Associated Methods​

These methods allow interaction with dependencies and relationships:

  • GetDependencyInfo
    Returns details on what the object depends on or what depends on it (useful for impact analysis). [learn.microsoft.com]
  • IsDependentUpon
    Returns True or False depending on whether the object relies on another specified object. [learn.microsoft.com]
 

Users who are viewing this thread

Back
Top Bottom