RE: error in background color change code



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
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


"Mary Fran" wrote:

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
.



Relevant Pages

  • Re: changing the background color of all controls
    ... controls on ALL forms in a database and received the response below - the ... Dim ThisControl As Control, SECTIONNUMBER As Integer, OldColour As Long ... NewColour = Forms!menumain.Section.BackColor ... ..BackColor = 8421376 Then ...
    (microsoft.public.access.modulesdaovba)
  • Re: changing the background color of all controls
    ... controls on ALL forms in a database and received the response below - the ... Dim ThisControl As Control, SECTIONNUMBER As Integer, OldColour As Long ... NewColour = Forms!menumain.Section.BackColor ... ..BackColor = 8421376 Then ...
    (microsoft.public.access.modulesdaovba)
  • Re: Change background color on all controls
    ... 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. ... Dim ThisControl As Control, SECTIONNUMBER As Integer, OldColour As Long ... NewColour = Forms!menumain.Section.BackColor ... ..BackColor = 8421376 Then ...
    (microsoft.public.access.formscoding)
  • Re: Change background color on all controls
    ... Dim ThisControl As Control, SECTIONNUMBER As Integer, OldColour As Long ... NewColour = Forms!menumain.Section.BackColor ... For Each ThisControl In .Controls ... ..BackColor = 8421376 Then ...
    (microsoft.public.access.formscoding)
  • error in background color change code
    ... controls on all forms in a database and received the response below - the ... Dim ThisControl As Control, SECTIONNUMBER As Integer, OldColour As Long ... NewColour = Forms!menumain.Section.BackColor ... ...BackColor = 8421376 Then ...
    (microsoft.public.access.formscoding)