Connecting Tech Pros Worldwide Help | Site Map

automate report in different mdb

xzzy
Guest
 
Posts: n/a
#1: Nov 12 '05
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


DFS
Guest
 
Posts: n/a
#2: Nov 12 '05

re: automate report in different mdb


Try leaving off the Properties(0).Name:

Set rpt = MyDB.Containers(5).Documents(i)




"xzzy" <mrbikejoc1@comcast.net> wrote in message
news:eAWyb.277096$9E1.1459853@attbi_s52...[color=blue]
> 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 =[/color]
MyDB.Containers(5).Documents(i).Properties(0).Name[color=blue]
>
>
>
> End If
> Next i
>
>
>
> Thank you for your help
>
>[/color]


xzzy
Guest
 
Posts: n/a
#3: Nov 12 '05

re: automate report in different mdb


Thank you, however using:

Set rpt = MyDB.Containers(5).Documents(0).Name

returns "Type Mis-match"


"DFS" <nospamDS@nospam.com> wrote in message
news:vsoduvghfgfub2@corp.supernews.com...[color=blue]
> Try leaving off the Properties(0).Name:
>
> Set rpt = MyDB.Containers(5).Documents(i)
>
>
>
>
> "xzzy" <mrbikejoc1@comcast.net> wrote in message
> news:eAWyb.277096$9E1.1459853@attbi_s52...[color=green]
> > 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 =[/color]
> MyDB.Containers(5).Documents(i).Properties(0).Name[color=green]
> >
> >
> >
> > End If
> > Next i
> >
> >
> >
> > Thank you for your help
> >
> >[/color]
>
>[/color]


Terry Kreft
Guest
 
Posts: n/a
#4: Nov 12 '05

re: automate report in different mdb



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" <mrbikejoc1@comcast.net> wrote in message
news:RT%yb.394135$Tr4.1148717@attbi_s03...[color=blue]
> Thank you, however using:
>
> Set rpt = MyDB.Containers(5).Documents(0).Name
>
> returns "Type Mis-match"
>
>
> "DFS" <nospamDS@nospam.com> wrote in message
> news:vsoduvghfgfub2@corp.supernews.com...[color=green]
> > Try leaving off the Properties(0).Name:
> >
> > Set rpt = MyDB.Containers(5).Documents(i)
> >
> >
> >
> >
> > "xzzy" <mrbikejoc1@comcast.net> wrote in message
> > news:eAWyb.277096$9E1.1459853@attbi_s52...[color=darkred]
> > > 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[/color][/color][/color]
design[color=blue][color=green][color=darkred]
> > > mode.
> > > 'The following line of code does not work:
> > > Set rpt =[/color]
> > MyDB.Containers(5).Documents(i).Properties(0).Name[color=darkred]
> > >
> > >
> > >
> > > End If
> > > Next i
> > >
> > >
> > >
> > > Thank you for your help
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


DFS
Guest
 
Posts: n/a
#5: Nov 12 '05

re: automate report in different mdb


xzzy,

It looks like "Terry" gave you a good answer, but it seems you didn't try my
suggestion correctly.

I said to try "Set rpt = MyDB.Containers(5).Documents(i)"

and you said you tried "Set rpt = MyDB.Containers(5).Documents(0).Name" and
it threw an error.




"xzzy" <mrbikejoc1@comcast.net> wrote in message
news:RT%yb.394135$Tr4.1148717@attbi_s03...[color=blue]
> Thank you, however using:
>
> Set rpt = MyDB.Containers(5).Documents(0).Name
>
> returns "Type Mis-match"
>
>
> "DFS" <nospamDS@nospam.com> wrote in message
> news:vsoduvghfgfub2@corp.supernews.com...[color=green]
> > Try leaving off the Properties(0).Name:
> >
> > Set rpt = MyDB.Containers(5).Documents(i)
> >
> >
> >
> >
> > "xzzy" <mrbikejoc1@comcast.net> wrote in message
> > news:eAWyb.277096$9E1.1459853@attbi_s52...[color=darkred]
> > > 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[/color][/color][/color]
design[color=blue][color=green][color=darkred]
> > > mode.
> > > 'The following line of code does not work:
> > > Set rpt =[/color]
> > MyDB.Containers(5).Documents(i).Properties(0).Name[color=darkred]
> > >
> > >
> > >
> > > End If
> > > Next i
> > >
> > >
> > >
> > > Thank you for your help
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Terry Kreft
Guest
 
Posts: n/a
#6: Nov 12 '05

re: automate report in different mdb


Whoops slight error

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

Should be

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
' Missing line follows
Exit For
Else
blnFound = False
End If
Next i

Terry

"Terry Kreft" <terry.kreft@mps.co.uk> wrote in message
news:bqi4n5$qdm$1@newsreaderg1.core.theplanet.net. ..[color=blue]
>
> Because the name property is a string type and your Rpt variable is of[/color]
type[color=blue]
> 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" <mrbikejoc1@comcast.net> wrote in message
> news:RT%yb.394135$Tr4.1148717@attbi_s03...[color=green]
> > Thank you, however using:
> >
> > Set rpt = MyDB.Containers(5).Documents(0).Name
> >
> > returns "Type Mis-match"
> >
> >
> > "DFS" <nospamDS@nospam.com> wrote in message
> > news:vsoduvghfgfub2@corp.supernews.com...[color=darkred]
> > > Try leaving off the Properties(0).Name:
> > >
> > > Set rpt = MyDB.Containers(5).Documents(i)
> > >
> > >
> > >
> > >
> > > "xzzy" <mrbikejoc1@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"[/color][/color][/color]
Then[color=blue][color=green][color=darkred]
> > > >
> > > >
> > > >
> > > > 'the following line works
> > > > DoCmd.OpenReport[/color][/color][/color]
MyDB.Containers(5).Documents(i).Name,[color=blue][color=green][color=darkred]
> > > > acViewDesign
> > > >
> > > > 'I need to set the object RPT to the remote report that is now in[/color][/color]
> design[color=green][color=darkred]
> > > > 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
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


xzzy
Guest
 
Posts: n/a
#7: Nov 12 '05

re: automate report in different mdb


Terry,

Thank you for your very helpful sample code.

John Bickmore
www.BicycleCam.com
www.Feed-Zone.com

"Terry Kreft" <terry.kreft@mps.co.uk> wrote in message
news:bqi4n5$qdm$1@newsreaderg1.core.theplanet.net. ..[color=blue]
>
> Because the name property is a string type and your Rpt variable is of[/color]
type[color=blue]
> 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" <mrbikejoc1@comcast.net> wrote in message
> news:RT%yb.394135$Tr4.1148717@attbi_s03...[color=green]
> > Thank you, however using:
> >
> > Set rpt = MyDB.Containers(5).Documents(0).Name
> >
> > returns "Type Mis-match"
> >
> >
> > "DFS" <nospamDS@nospam.com> wrote in message
> > news:vsoduvghfgfub2@corp.supernews.com...[color=darkred]
> > > Try leaving off the Properties(0).Name:
> > >
> > > Set rpt = MyDB.Containers(5).Documents(i)
> > >
> > >
> > >
> > >
> > > "xzzy" <mrbikejoc1@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"[/color][/color][/color]
Then[color=blue][color=green][color=darkred]
> > > >
> > > >
> > > >
> > > > 'the following line works
> > > > DoCmd.OpenReport[/color][/color][/color]
MyDB.Containers(5).Documents(i).Name,[color=blue][color=green][color=darkred]
> > > > acViewDesign
> > > >
> > > > 'I need to set the object RPT to the remote report that is now in[/color][/color]
> design[color=green][color=darkred]
> > > > 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
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread