Programmatically Changing Form Appearance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have an ever-growing multi-purpose application whose grey forms have
become a little tired-looking. We'd like to make some simple changes to
color and positions of the title and eyebrow from their current locations,
etc. The title and eyebrow are in a consistent place form to form. Since
there about 100 forms, I'd like to do this programmatically.

I don't know how to:

- Cycle through the Forms collection
- Refer to a specific portion of the form, such as the Detail or Heading
sections

Can anybody point me in the right direction?

Thank you.
Sprinks
 
Sprinks said:
We have an ever-growing multi-purpose application whose grey forms have
become a little tired-looking. We'd like to make some simple changes to
color and positions of the title and eyebrow from their current locations,
etc. The title and eyebrow are in a consistent place form to form. Since
there about 100 forms, I'd like to do this programmatically.

I don't know how to:

- Cycle through the Forms collection
- Refer to a specific portion of the form, such as the Detail or Heading
sections

Can anybody point me in the right direction?


I have no idea what you mean by "eyebrow". If you mean the
title bar, then you can not change its color because that's
a Windows Display Property, not an Access setting.

You can loop through the open forms using:
Dim frm As Form
For Each frm in Forms
frm.Caption = "some text here"
. . .
Next frm

OTOH, it almost sounds like you want to do this for all
forms as a design change instead of at runtime. In this
case, you can use the Forms Container to locate the name of
each form Document. In later versions of Access it's easier
to use the AllForms collection.

Dim fobj As AccessObject
For Each fobj In Application.AllForms
DoCmd.OpenForm fobj.Name, acDesign
With Forms(fobj.Name)
.Caption = "some text here"
. . .
End With
DoCmd.Close acForm, fobj.Name, acSaveYes
Next fobj
 
Marshall,

Thanks for your clear response; it's exactly what I needed.

BTW, the "eyebrow" reference was arcane jargon from my days of writing
product literature. In this case, it's a textbox that displays the purpose
of the form, located directly underneath the title.

Thanks again.
 
Marshall,

I spoke too soon. I placed the code in a Utility module, and placed a
command to call it. An error was generated "Method or data member not
found", with the debugger highlighting "AllForms". I'm using Access 2002
(10.2627.2625). I figured it might be a missing reference. Do you know
which one? I also wondered if the form my button is on would generate an
error when the code attempted to close IT.

Also, I changed the code to the following, testing it on a single form. It
generated the error "Operation is not supported for this type of object",
highlighting the For Each... line. Do you know what this means?

Thank you.

Sprinks

Public Sub UpdateForms()
' Loop through Forms container
Dim db As Database
Dim fobj As AccessObject

Set db = CurrentDb()
For Each fobj In db.Containers!Forms
'Application.AllForms
DoCmd.OpenForm fobj.name, acDesign
If fobj.name = "DuctTakeoffInit" Then
With Forms(fobj.name)
.FormHeader.BackColor = 255
.Detail.BackColor = 16777215
.FormFooter.BackColor = 16711680
End With
End If
DoCmd.Close acForm, fobj.name, acSaveYes
Next fobj
End Sub
 
You changed to using the Containers collection, but forgot
that an element in that collection is a Documents
collection. This doesn't matter because the AllForms
collection works in A2002.

I had a mental lapse, the For Each statement should be:

For Each fobj In CurrentProject.AllForms
 
Marshall,

Awesome. This is a BIG arrow in my quiver.

Thank you.

Sprinks

Marshall Barton said:
You changed to using the Containers collection, but forgot
that an element in that collection is a Documents
collection. This doesn't matter because the AllForms
collection works in A2002.

I had a mental lapse, the For Each statement should be:

For Each fobj In CurrentProject.AllForms
--
Marsh
MVP [MS Access]

I spoke too soon. I placed the code in a Utility module, and placed a
command to call it. An error was generated "Method or data member not
found", with the debugger highlighting "AllForms". I'm using Access 2002
(10.2627.2625). I figured it might be a missing reference. Do you know
which one? I also wondered if the form my button is on would generate an
error when the code attempted to close IT.

Also, I changed the code to the following, testing it on a single form. It
generated the error "Operation is not supported for this type of object",
highlighting the For Each... line. Do you know what this means?

Public Sub UpdateForms()
' Loop through Forms container
Dim db As Database
Dim fobj As AccessObject

Set db = CurrentDb()
For Each fobj In db.Containers!Forms
'Application.AllForms
DoCmd.OpenForm fobj.name, acDesign
If fobj.name = "DuctTakeoffInit" Then
With Forms(fobj.name)
.FormHeader.BackColor = 255
.Detail.BackColor = 16777215
.FormFooter.BackColor = 16711680
End With
End If
DoCmd.Close acForm, fobj.name, acSaveYes
Next fobj
End Sub
 
If you're familar with DAO, you can use it to open the MSysObject table
and look for objects with the Type -32768. When you encounter one, you
can open it in design view and change the properties for the various
sections using...

Detail
PageHeader
PageFooter
FormHeader
FormFooter

as their names. These, of course, are the DEFAULT names for the
sections. As long as you haven't changed them, there shouldn't be a problem.

***WORD OF ADVICE*** I would create a backup copy of the database FIRST
before trying this and DEFINETLY for testing & development.
 
Thanks, David.

David C. Holley said:
If you're familar with DAO, you can use it to open the MSysObject table
and look for objects with the Type -32768. When you encounter one, you
can open it in design view and change the properties for the various
sections using...

Detail
PageHeader
PageFooter
FormHeader
FormFooter

as their names. These, of course, are the DEFAULT names for the
sections. As long as you haven't changed them, there shouldn't be a problem.

***WORD OF ADVICE*** I would create a backup copy of the database FIRST
before trying this and DEFINETLY for testing & development.
 
You may want to do something where you document any form that you're not
able to modify programically and then examine each. Basically, if you
try to reference the sections by the default names and are unable to do
so, the section was probably renamed.
 
Back
Top