Replace Function

bharlow

Registered User.
Local time
Today, 09:26
Joined
Dec 26, 2008
Messages
52
Is there a way to replace the title/header for all reports in a DB at one time?

For example...I want to change the Report titles for about 50 reports from XXXX - SOUTH to XXXX - NORTHWEST without having to open all 50 reports.
 
yes.

open the reports collection, change what you want and save the changes.

Q&D:
Code:
Public Function ChangeReportCaption(strNewCaption As String) As Boolean

    Dim dbs As Database
    Dim doc As Document
    Dim rpt As Report
    
    Set dbs = CurrentDb
    
    For Each doc In dbs.Containers("Reports").Documents
        Debug.Print doc.Name;
        DoCmd.OpenReport doc.Name, acViewDesign, , , acHidden
        Set rpt = Reports(doc.Name)
        Debug.Print rpt.Caption
        rpt.Caption = Replace(rpt.Caption, "XXXX", strNewCaption)
        Debug.Print rpt.Caption
        DoCmd.Close acReport, doc.Name, acSaveYes
    Next doc
    
End Function
Bare in mind that this function works only once. Because second time it won't find XXXX because you changed it.

Enjoy!
 

Users who are viewing this thread

Back
Top Bottom