Programatically change a property in all reports

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a database with hundreds of reports. I want to change a property in
all of them. How do I do it programmatically in vba? I have not worked with
the reports object model before.
Thanks,
Loren
 
I have a database with hundreds of reports. I want to change a property in
all of them. How do I do it programmatically in vba? I have not worked with
the reports object model before.
Thanks,
Loren

What property?
You asked a generic question, here's a generic reply.

In a module, cycle through each report in the report collection,
opening each in turn in design view, change the property, close and
save the changes, repeat for the next report.
 
I think I have figured it out - if anyone wants to programatically change
properties in all reports in a collection. This was especially helpful for
me as I am working with a database that has gone through many changes and
versions:

Private Sub cmdSetObjectProperties()
On Error GoTo Err_cmdSetObjectProperties
Dim obj As AccessObject, dbs As Object, objName As String
Set dbs = Application.CurrentProject
' Search for all AccessObject objects in the AllReports collection.
'TURN SCREEN FUNCTIONS OFF
DoCmd.Hourglass True
DoCmd.Echo False, "Processing, please wait!"
DoCmd.SetWarnings False
For Each obj In dbs.AllReports
objName = obj.Name
'OPEN THE REPORT
DoCmd.OpenReport objName, acViewDesign
'SET THE PROPERTY(S) - THESE ARE JUST A FEW
Reports(objName).AutoResize = False
Reports(objName).AutoCenter = True
Reports(objName).BorderStyle = 1
Reports(objName).MinMaxButtons = 0
Reports(objName).Moveable = False
'CLOSE AND SAVE THE REPORT
DoCmd.Close acReport, objName, acSaveYes
Next obj
'TURN SCREEN FUNCTIONS BACK ON
DoCmd.Echo True
DoCmd.Hourglass False
DoCmd.SetWarnings True

MsgBox "Properties set successfully!", vbExclamation

Exit_cmdSetObjectProperties:
Exit Sub
Err_cmdSetObjectProperties:
DoCmd.Echo True
DoCmd.Hourglass False
DoCmd.SetWarnings True
MsgBox "Error Number: " & Err.Number & " " & Err.Description
Resume Exit_cmdSetObjectProperties
End Sub

Loren
 
Thank you for a perfect solution!

I think I have figured it out - if anyone wants to programatically change
properties in all reports in a collection. This was especially helpful for
me as I am working with a database that has gone through many changes and
versions:

Private Sub cmdSetObjectProperties()
On Error GoTo Err_cmdSetObjectProperties
Dim obj As AccessObject, dbs As Object, objName As String
Set dbs = Application.CurrentProject
' Search for all AccessObject objects in the AllReports collection.
'TURN SCREEN FUNCTIONS OFF
DoCmd.Hourglass True
DoCmd.Echo False, "Processing, please wait!"
DoCmd.SetWarnings False
For Each obj In dbs.AllReports
objName = obj.Name
'OPEN THE REPORT
DoCmd.OpenReport objName, acViewDesign
'SET THE PROPERTY(S) - THESE ARE JUST A FEW
Reports(objName).AutoResize = False
Reports(objName).AutoCenter = True
Reports(objName).BorderStyle = 1
Reports(objName).MinMaxButtons = 0
Reports(objName).Moveable = False
'CLOSE AND SAVE THE REPORT
DoCmd.Close acReport, objName, acSaveYes
Next obj
'TURN SCREEN FUNCTIONS BACK ON
DoCmd.Echo True
DoCmd.Hourglass False
DoCmd.SetWarnings True

MsgBox "Properties set successfully!", vbExclamation

Exit_cmdSetObjectProperties:
Exit Sub
Err_cmdSetObjectProperties:
DoCmd.Echo True
DoCmd.Hourglass False
DoCmd.SetWarnings True
MsgBox "Error Number: " & Err.Number & " " & Err.Description
Resume Exit_cmdSetObjectProperties
End Sub

Loren


"Loren" wrote:

> I have a database with hundreds of reports. I want to change a property in
> all of them. How do I do it programmatically in vba? I have not worked with
> the reports object model before.
> Thanks,
> Loren
 
Back
Top