loop thru all forms to change properties

M

Mark Kubicki

i want to add a command that will update header.backcolor... in (all) of the
forms with in the current project...and am using the following code
(below)...
it loops thru the forms correctly, but does not change the color...
Is there a caviat i'm missing?

Private Sub Form_Open(Cancel As Integer)
Dim frm As Object
For Each frm In CurrentProject.AllForms
If Mid(frm.Name, 1, 3) = "frm" Then
FormHeader.BackColor = 11528154
txtHeaderTitle.ForeColor = 108
End If
Next frm
End Sub


thanks in advance,
mark
 
K

Klatuu

You have to open each form in design view (it can be hidden), make the change
and save the form:

Private Sub Form_Open(Cancel As Integer)
Dim frm As Object
For Each frm In CurrentProject.AllForms
If Left(frm.Name, 1, 3) = "frm" Then
Docmd.OpenForm frm.Name, acDesign, , , ,acHidden
frm.FormHeader.BackColor = 11528154
frm.txtHeaderTitle.ForeColor = 108
Docmd.Close acForm, Me.Name, acSaveYes
End If
Next frm
End Sub
 
D

Dirk Goldgar

in message
i want to add a command that will update header.backcolor... in (all) of
the forms with in the current project...and am using the following code
(below)...
it loops thru the forms correctly, but does not change the color...
Is there a caviat i'm missing?

Private Sub Form_Open(Cancel As Integer)
Dim frm As Object
For Each frm In CurrentProject.AllForms
If Mid(frm.Name, 1, 3) = "frm" Then
FormHeader.BackColor = 11528154
txtHeaderTitle.ForeColor = 108
End If
Next frm
End Sub


It seems odd that you would be doing this in the Open event of a form, but
the issue with your code is that you need to open each form in design view,
make the change to that form object, and save it. Since you're using a
form's Open event to run the code, you'll have to exclude that form from the
ones that are processed. Try something like this:

Private Sub Form_Open(Cancel As Integer)

Dim ao As AccessObject

For Each ao In CurrentProject.AllForms

If Left(ao.Name, 3) = "frm" _
And ao.Name <> Me.Name _
Then

DoCmd.OpenForm ao.Name, acDesign, _
WindowMode:=acHidden

With Forms(ao.Name)
.FormHeader.BackColor = 11528154
!txtHeaderTitle.ForeColor = 108
End With

DoCmd.Close acForm, ao.Name, acSaveYes

End If

Next ao

End Sub
 
M

Mark Kubicki

what would a better event to use be
the code is behind the main menu form, and i want the project's properties
to update each time it's run.?

-mark
 
D

Dirk Goldgar

Mark Kubicki said:
what would a better event to use be
the code is behind the main menu form, and i want the project's properties
to update each time it's run.?


I can't say what would be a better event to use. The Open event of the main
menu form may be appropriate, if you really need to do this every time the
application is opened. But it's very unusual to make extensive design
changes at runtime. Why do you want to do this? Maybe it would be better
to store the desired property values in a table, and then have each form
check that table in its Open event and *temporarily* set its properties
accordingly. Then there'd be no need to go into design view or save the
design change.
 
A

AccessVandal via AccessMonster.com

Try this if it works for you.

Mark Kubicki wrote:
i want to add a command that will update header.backcolor... in (all) of the
forms with in the current project...and am using the following code
(below)...
it loops thru the forms correctly, but does not change the color...
Is there a caviat i'm missing?

Private Sub Form_Open(Cancel As Integer)

Forms!YourFormName.Section(1).BackColor = 11528154

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top