Object

  • Thread starter Thread starter dale
  • Start date Start date
D

dale

If I want to use the following code I get a run-time error 438. I am
assuming I am missing a reference but do not know which one to include
for this.

Dim obj As Object
Dim db As DAO.Database
Set db = CurrentDb
For Each obj In db.Containers
If obj.Type = acReport Then
obj.Properties("AutoResize") = "No"
End If
Next obj

Any help is appreciated

Dale Brown
 
If I want to use the following code I get a run-time error 438. I am
assuming I am missing a reference but do not know which one to include
for this.

Dim obj As Object
Dim db As DAO.Database
Set db = CurrentDb
For Each obj In db.Containers
If obj.Type = acReport Then
obj.Properties("AutoResize") = "No"
End If
Next obj

Any help is appreciated

Dale Brown

It's not a problem with your references, assuming you have a reference
set to DAO. But your code is not using the object model correctly. Try
this -- it's air code, but should be close to right:

' ---- set AutoResize = False ("No") for all reports ----

Dim db As DAO.Database
Dim cnt As DAO.Container
Dim doc As DAO.Document

Set db = CurrentDb
Set cnt = db.Containers("Reports")

For each doc in cnt.Documents

DoCmd.OpenReport doc.Name,acViewDesign, _
WindowMode:=acHidden

Reports(doc.Name).AutoResize = False

DoCmd.Close acReport, doc.Name, acSaveYes

Next doc

Set cnt = Nothing
Set doc = Nothing
 
Dirk,

Thanks that worked. Do you know how to set the size of the report to
show the whole width of the page when it is in print preview mode for
all of these reports.

Dale
 
Dirk,

Thanks that worked. Do you know how to set the size of the report to
show the whole width of the page when it is in print preview mode for
all of these reports.

I don't believe this is something you can set for the report at design
time. I'm not sure if this is what you're after, but you may be
interested in using the following function to open your reports:

'----- start of code -----
Sub OpenAndZoomReport(ReportName As String)

On Error GoTo Err_OpenAndZoomReport

DoCmd.OpenReport ReportName, acViewPreview
DoCmd.Maximize
RunCommand acCmdFitToWindow

Exit_OpenAndZoomReport:
Exit Sub

Err_OpenAndZoomReport:
MsgBox Err.Description, _
vbExclamation, _
"Error " & Err.Number & " Opening Report"
Resume Exit_OpenAndZoomReport

End Sub
----- end of code -----

I'm not sure where I got it.
 
Back
Top