error in background color change code

G

Guest

Hi - I requested help this morning in changing the background color of all
controls on all forms in a database and received the response below - the
problem is I get a Data type mismatch at this line of code: For Each Doc In
Ctr.Documents
Am I possibly missing a reference? Thanks.

(Response)
This is the function that I use to change the colour of all forms and
controls, it is set up for the style that I use but you should be able to
pick
out the bits that you want and adapt them to your needs.

Public Sub FormColourAll(NewColour As Long)
On Error GoTo Err_FormColourAll
Dim Thisdb As Database, Ctr As Container, Doc As Document, ThisForm As Form
Dim ThisControl As Control, SECTIONNUMBER As Integer, OldColour As Long
If NewColour = 0 Then
DoCmd.OpenForm "MenuMain", acDesign
NewColour = Forms!menumain.Section(acDetail).BackColor
DoCmd.Close
End If
Set Thisdb = CurrentDb
Set Ctr = Thisdb.Containers!Forms
For Each Doc In Ctr.Documents
DoCmd.OpenForm Doc.Name, acDesign
Set ThisForm = Forms(Doc.Name)
With ThisForm
For SECTIONNUMBER = 0 To 4
OldColour = .Section(SECTIONNUMBER).BackColor
If OldColour > 0 Then
.Section(SECTIONNUMBER).BackColor = NewColour
For Each ThisControl In .Controls
With ThisControl
Select Case .ControlType
Case acTextBox, acLabel
If .BackColor = 12632256 And .SpecialEffect =
acEffectRaised Then
.BackColor = vbButtonFace
ElseIf .BackColor = OldColour Or .BackColor = 16748800 Or
...BackColor = 8421376 Then
.BackColor = NewColour
End If
If .ControlType = acTextBox Then .AllowAutoCorrect = False
Case acRectangle, acOptionGroup, acListBox, acComboBox
If .BackColor = OldColour Or .BackColor = 16748800 Then
.BackColor = NewColour
End If
If .ControlType = acComboBox Then .AllowAutoCorrect = False
End Select
End With
Next ThisControl
End If
Next SECTIONNUMBER
End With
DoCmd.Close , , acSaveYes
Next Doc
Set Doc = Nothing
Set Ctr = Nothing
Set ThisControl = Nothing
Set ThisForm = Nothing
Set Thisdb = Nothing

Exit_FormColourAll:
Exit Sub

Err_FormColourAll:
If Err = 2462 Then
Resume Next
Else
msgbox "FormColourAll Error " & Err & " - " & Error$
Resume Exit_FormColourAll
End If
End Sub

HTH
John
##################################
Don't Print - Save trees
 
G

Guest

Hi Mary Fran,

According to the Object Browser, "Container" is a member of DAO, so you
should have a reference set for

Microsoft DAO 3.6 Object Library

HTH
 

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