Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Background Colour 1

Status
Not open for further replies.

drewduncan

Programmer
Apr 3, 2003
38
0
0
GB
Hi:

I am redesigning the front end of an access 2000 database. I am looking at changing the background colour of all forms.

Does anyone know how this can be done in code to prevent myself from having to manually change the value on every form.

Any help as always greatly appreciated.

Cheers.
 
Hi,

Use this:
Code:
Sub ChangeFormColours(lngOldColour As Long, lngNewColour As Long)

    Dim obj As AccessObject
    Dim frm As Form
    Dim intSectionLoop As Integer
    
    For Each obj In CurrentProject.AllForms
        DoCmd.OpenForm obj.Name, acDesign
        Set frm = Forms(obj.Name)
        
        If frm.Section(acDetail).BackColor = lngOldColour Then
            On Error Resume Next
            For intSectionLoop = 0 To 4
                frm.Section(intSectionLoop).BackColor = lngNewColour
            Next
            Debug.Print frm.Name
        End If
        DoCmd.Close acForm, frm.Name, acSaveYes
    Next
End Sub

This will only look for forms with a specified background colour. You can comment out this If statement to get it to change every forms colour:

If frm.Section(acDetail).BackColor = lngOldColour Then (Don't forget the EndIf)

Call the procedure from the immediate window using the syntax:
Code:
ChangeFormColours -2147483633,16777215
The first number is the original number from the Back Color property. Select the new background colour you want and use that as the second argument. It changes all sections (Form Header, Page Header, Detail etc...). It also prints the names of all the forms changed in the immediate window for reference.

If you need any more help let me know.

HTH

Dean :)
 
mind if i join in with a question: would there be any way to restrict (by the process of inclusion and then the process of exclusion) which forms were impacted on by this code (over and above the issue of color number value)?. say, there are dozens of forms but you really don't want certain ones changed -- OR -- say there are only a few forms you want changed but too many to feel good about the idea of doing it manually in the properties window, i.e. 50 out of 100?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top