Because the name property is a string type and your Rpt variable is of type
Report.
The method you are trying to use is wrong, have a look at something like
Dim App As Access.Application
Dim myDb As DAO.Database
Dim strDBPath As String
Dim RPT As Access.Report
Dim blnFound As Boolean
Const REPORT_NAME = "MyReport"
strDBPath = Application.CurrentProject.Path & "\Mydb.mdb"
Set App = New Access.Application
With App
.OpenCurrentDatabase strDBPath, True
Set myDb = .CurrentDb
End With
For i = 0 To myDb.Containers(5).Documents.Count - 1
If myDb.Containers(5).Documents(i).Name = REPORT_NAME Then
App.DoCmd.OpenReport REPORT_NAME, acViewDesign
Set RPT = App.Reports(REPORT_NAME)
blnFound = True
Else
blnFound = False
End If
Next i
If blnFound Then
' Do whatever you want with the report
End If
App.DoCmd.Close acReport, REPORT_NAME, acSaveYes
Set RPT = Nothing
App.Quit acQuitSaveAll
Set myDb = Nothing
Set App = Nothing
Terry
"xzzy" <mr********@comcast.net> wrote in message
news:RT%yb.394135$Tr4.1148717@attbi_s03...
Thank you, however using:
Set rpt = MyDB.Containers(5).Documents(0).Name
returns "Type Mis-match"
"DFS" <no******@nospam.com> wrote in message
news:vs************@corp.supernews.com... Try leaving off the Properties(0).Name:
Set rpt = MyDB.Containers(5).Documents(i)
"xzzy" <mr********@comcast.net> wrote in message
news:eAWyb.277096$9E1.1459853@attbi_s52... I need to automate a report in a different database.
Dim RPT as Report
Set MyDB = wrkJet.OpenDatabase(Application.CurrentProject.Pat h &
"\Mydb.mdb", True, False)
For i = 0 To MyDB.Containers(5).Documents.Count - 1
If MyDB.Containers(5).Documents(i).Name = "MyReport" Then
'the following line works
DoCmd.OpenReport MyDB.Containers(5).Documents(i).Name,
acViewDesign
'I need to set the object RPT to the remote report that is now in
design mode.
'The following line of code does not work:
Set rpt =
MyDB.Containers(5).Documents(i).Properties(0).Name
End If
Next i
Thank you for your help