Accessing forms properties

  • Thread starter Thread starter peterDavey
  • Start date Start date
P

peterDavey

G'day,
I'm pretty new to Access but have Excel VBA experience.

I have an Access 2000 application with a number of forms and sub-forms. At
startup I display a form with a list box listing the forms I may want to
use. At the moment the form names are hard coded into the list boxe's
DataSource property.

What I want to do is use the Tag property of each form to flag the forms
that I want listed in the list box. When the 'menu' form opens I need the
code to loop through all forms and, where the tag property doesn't = 0, add
it to the list box.

I've found that using the AllForms collection gives me access to all the
forms however I haven't been able to successfully access the Tag property
using the Properties collection. Using the code:

MsgBox
Application.CurrentProject.AllForms("Wards").Properties("Tag").Value

generates an error: 'you entered an expression that has an invalid reference
to the tag property'

Not sure what I'm doing wrong.

cheers
peterDavey
Melbourne
 
As you found, properties like Tag are not available through the AllForms
collection.

You could create a custom property for the Document, to indicate whether to
include it. The document can be accessed like this:
CurrentDb().Containers("Forms").Documents("Form1")
You can create a property with a name like "ListToUser", of type dbBoolean,
and set it to True for the form names you want to show.

You can then read the properties from this collection without having to open
each form (hidden) to retrieve the property. The reference would be:
CurrentDb().Containers("Forms").Documents("Form1").Properties("ListToUser")

If you have lots of forms, the most efficient approach would be to load the
list box with a call-back function. There is an example of loading reports
that way in:
List Box of Available Reports
at:
http://allenbrowne.com/ser-19.html
The reads the names from the Documents collection, and loads them into a
static array, so it would be easy enough to modify it so only those with the
custom property set to True are loaded.

If you have never worked with custom properties, there's a downloadable
example in this article:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html
The example uses a custom property so that each report remembers which
printer it is supposed to go to.

HTH
 
peterDavey said:
I'm pretty new to Access but have Excel VBA experience.

I have an Access 2000 application with a number of forms and sub-forms. At
startup I display a form with a list box listing the forms I may want to
use. At the moment the form names are hard coded into the list boxe's
DataSource property.

What I want to do is use the Tag property of each form to flag the forms
that I want listed in the list box. When the 'menu' form opens I need the
code to loop through all forms and, where the tag property doesn't = 0, add
it to the list box.

I've found that using the AllForms collection gives me access to all the
forms however I haven't been able to successfully access the Tag property
using the Properties collection. Using the code:

MsgBox
Application.CurrentProject.AllForms("Wards").Properties("Tag").Value

generates an error: 'you entered an expression that has an invalid reference
to the tag property'


A form's (and report's) properties are only available when
it's open. The AllForms collection only provides the name
of the application's forms and a few other things like its
IsLoaded property.

Unless you plan on opening every form in your app before you
display the list box, you can not use the tag property for
this.

OTOH, I think I remember that the
Containers("Forms").Documents collection will provide you
with all the forms and that you can create a custom property
for each Document to do what you want.
 
Thanks Allen and Marsh for your replies. The Container().Documents...
solution looks like the way to go - much better than using the Tag property.
cheers
peterD
 
PeterDavey

Here is another way to do this.

In that Access is a database why not use its inherent database capability to
create a Table of Forms, and keep all of the information about each form in
your application there. After all this is the way Access manages itself
(have a look at the system tables). You might have columns for user
friendly short names, verbose names, and the actual form names that the user
never sees. Need to add security later? Now you have a way to keep the
list of forms shown in your List Box synchronized to the users rights, by
simply adding a new column to the table.

This system would be no harder to maintain that an entry into the forms Tag
property or a custom property. This way the record source for the combo
becomes a Sql statement (also a very Access way of doing things). I believe
this is a more flexible and extensible way to manage the list of forms that
the user interacts with.

Good luck with your project.
 
Ron,
Thanks for your reply. I had thought of developing a 'user interface'
module in the database sometime in the future. I was looking to use the
tags as a 'quick and dirty' short time solution. On reflection I might go
with the table because, as the number of forms increases, I'll want to
categorize them but the biggest advantage will be that using a query I'll be
able to easily sort the list.

cheers
peterD
 
Back
Top