automate report in different mdb

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • xzzy

    automate report in different mdb

    I need to automate a report in a different database.

    Dim RPT as Report

    Set MyDB = wrkJet.OpenData base(Applicatio n.CurrentProjec t.Path &
    "\Mydb.mdb" , True, False)

    For i = 0 To MyDB.Containers (5).Documents.C ount - 1
    If MyDB.Containers (5).Documents(i ).Name = "MyReport" Then



    'the following line works
    DoCmd.OpenRepor t 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

    #2
    Re: automate report in different mdb

    Try leaving off the Properties(0).N ame:

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




    "xzzy" <mrbikejoc1@com cast.net> wrote in message
    news:eAWyb.2770 96$9E1.1459853@ attbi_s52...[color=blue]
    > I need to automate a report in a different database.
    >
    > Dim RPT as Report
    >
    > Set MyDB = wrkJet.OpenData base(Applicatio n.CurrentProjec t.Path &
    > "\Mydb.mdb" , True, False)
    >
    > For i = 0 To MyDB.Containers (5).Documents.C ount - 1
    > If MyDB.Containers (5).Documents(i ).Name = "MyReport" Then
    >
    >
    >
    > 'the following line works
    > DoCmd.OpenRepor t 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]


    Comment

    • xzzy

      #3
      Re: automate report in different mdb

      Thank you, however using:

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

      returns "Type Mis-match"


      "DFS" <nospamDS@nospa m.com> wrote in message
      news:vsoduvghfg fub2@corp.super news.com...[color=blue]
      > Try leaving off the Properties(0).N ame:
      >
      > Set rpt = MyDB.Containers (5).Documents(i )
      >
      >
      >
      >
      > "xzzy" <mrbikejoc1@com cast.net> wrote in message
      > news:eAWyb.2770 96$9E1.1459853@ attbi_s52...[color=green]
      > > I need to automate a report in a different database.
      > >
      > > Dim RPT as Report
      > >
      > > Set MyDB = wrkJet.OpenData base(Applicatio n.CurrentProjec t.Path &
      > > "\Mydb.mdb" , True, False)
      > >
      > > For i = 0 To MyDB.Containers (5).Documents.C ount - 1
      > > If MyDB.Containers (5).Documents(i ).Name = "MyReport" Then
      > >
      > >
      > >
      > > 'the following line works
      > > DoCmd.OpenRepor t 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]


      Comment

      • Terry Kreft

        #4
        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.Applicat ion
        Dim myDb As DAO.Database
        Dim strDBPath As String
        Dim RPT As Access.Report
        Dim blnFound As Boolean

        Const REPORT_NAME = "MyReport"

        strDBPath = Application.Cur rentProject.Pat h & "\Mydb.mdb"
        Set App = New Access.Applicat ion

        With App
        .OpenCurrentDat abase strDBPath, True
        Set myDb = .CurrentDb
        End With

        For i = 0 To myDb.Containers (5).Documents.C ount - 1
        If myDb.Containers (5).Documents(i ).Name = REPORT_NAME Then
        App.DoCmd.OpenR eport REPORT_NAME, acViewDesign
        Set RPT = App.Reports(REP ORT_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@com cast.net> wrote in message
        news:RT%yb.3941 35$Tr4.1148717@ attbi_s03...[color=blue]
        > Thank you, however using:
        >
        > Set rpt = MyDB.Containers (5).Documents(0 ).Name
        >
        > returns "Type Mis-match"
        >
        >
        > "DFS" <nospamDS@nospa m.com> wrote in message
        > news:vsoduvghfg fub2@corp.super news.com...[color=green]
        > > Try leaving off the Properties(0).N ame:
        > >
        > > Set rpt = MyDB.Containers (5).Documents(i )
        > >
        > >
        > >
        > >
        > > "xzzy" <mrbikejoc1@com cast.net> wrote in message
        > > news:eAWyb.2770 96$9E1.1459853@ attbi_s52...[color=darkred]
        > > > I need to automate a report in a different database.
        > > >
        > > > Dim RPT as Report
        > > >
        > > > Set MyDB = wrkJet.OpenData base(Applicatio n.CurrentProjec t.Path &
        > > > "\Mydb.mdb" , True, False)
        > > >
        > > > For i = 0 To MyDB.Containers (5).Documents.C ount - 1
        > > > If MyDB.Containers (5).Documents(i ).Name = "MyReport" Then
        > > >
        > > >
        > > >
        > > > 'the following line works
        > > > DoCmd.OpenRepor t 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]


        Comment

        • DFS

          #5
          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@com cast.net> wrote in message
          news:RT%yb.3941 35$Tr4.1148717@ attbi_s03...[color=blue]
          > Thank you, however using:
          >
          > Set rpt = MyDB.Containers (5).Documents(0 ).Name
          >
          > returns "Type Mis-match"
          >
          >
          > "DFS" <nospamDS@nospa m.com> wrote in message
          > news:vsoduvghfg fub2@corp.super news.com...[color=green]
          > > Try leaving off the Properties(0).N ame:
          > >
          > > Set rpt = MyDB.Containers (5).Documents(i )
          > >
          > >
          > >
          > >
          > > "xzzy" <mrbikejoc1@com cast.net> wrote in message
          > > news:eAWyb.2770 96$9E1.1459853@ attbi_s52...[color=darkred]
          > > > I need to automate a report in a different database.
          > > >
          > > > Dim RPT as Report
          > > >
          > > > Set MyDB = wrkJet.OpenData base(Applicatio n.CurrentProjec t.Path &
          > > > "\Mydb.mdb" , True, False)
          > > >
          > > > For i = 0 To MyDB.Containers (5).Documents.C ount - 1
          > > > If MyDB.Containers (5).Documents(i ).Name = "MyReport" Then
          > > >
          > > >
          > > >
          > > > 'the following line works
          > > > DoCmd.OpenRepor t 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]


          Comment

          • Terry Kreft

            #6
            Re: automate report in different mdb

            Whoops slight error

            For i = 0 To myDb.Containers (5).Documents.C ount - 1
            If myDb.Containers (5).Documents(i ).Name = REPORT_NAME Then
            App.DoCmd.OpenR eport REPORT_NAME, acViewDesign
            Set RPT = App.Reports(REP ORT_NAME)
            blnFound = True
            Else
            blnFound = False
            End If
            Next i

            Should be

            For i = 0 To myDb.Containers (5).Documents.C ount - 1
            If myDb.Containers (5).Documents(i ).Name = REPORT_NAME Then
            App.DoCmd.OpenR eport REPORT_NAME, acViewDesign
            Set RPT = App.Reports(REP ORT_NAME)
            blnFound = True
            ' Missing line follows
            Exit For
            Else
            blnFound = False
            End If
            Next i

            Terry

            "Terry Kreft" <terry.kreft@mp s.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.Applicat ion
            > Dim myDb As DAO.Database
            > Dim strDBPath As String
            > Dim RPT As Access.Report
            > Dim blnFound As Boolean
            >
            > Const REPORT_NAME = "MyReport"
            >
            > strDBPath = Application.Cur rentProject.Pat h & "\Mydb.mdb"
            > Set App = New Access.Applicat ion
            >
            > With App
            > .OpenCurrentDat abase strDBPath, True
            > Set myDb = .CurrentDb
            > End With
            >
            > For i = 0 To myDb.Containers (5).Documents.C ount - 1
            > If myDb.Containers (5).Documents(i ).Name = REPORT_NAME Then
            > App.DoCmd.OpenR eport REPORT_NAME, acViewDesign
            > Set RPT = App.Reports(REP ORT_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@com cast.net> wrote in message
            > news:RT%yb.3941 35$Tr4.1148717@ attbi_s03...[color=green]
            > > Thank you, however using:
            > >
            > > Set rpt = MyDB.Containers (5).Documents(0 ).Name
            > >
            > > returns "Type Mis-match"
            > >
            > >
            > > "DFS" <nospamDS@nospa m.com> wrote in message
            > > news:vsoduvghfg fub2@corp.super news.com...[color=darkred]
            > > > Try leaving off the Properties(0).N ame:
            > > >
            > > > Set rpt = MyDB.Containers (5).Documents(i )
            > > >
            > > >
            > > >
            > > >
            > > > "xzzy" <mrbikejoc1@com cast.net> wrote in message
            > > > news:eAWyb.2770 96$9E1.1459853@ attbi_s52...
            > > > > I need to automate a report in a different database.
            > > > >
            > > > > Dim RPT as Report
            > > > >
            > > > > Set MyDB = wrkJet.OpenData base(Applicatio n.CurrentProjec t.Path &
            > > > > "\Mydb.mdb" , True, False)
            > > > >
            > > > > For i = 0 To MyDB.Containers (5).Documents.C ount - 1
            > > > > If MyDB.Containers (5).Documents(i ).Name = "MyReport"[/color][/color][/color]
            Then[color=blue][color=green][color=darkred]
            > > > >
            > > > >
            > > > >
            > > > > 'the following line works
            > > > > DoCmd.OpenRepor t[/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]


            Comment

            • xzzy

              #7
              Re: automate report in different mdb

              Terry,

              Thank you for your very helpful sample code.

              John Bickmore



              "Terry Kreft" <terry.kreft@mp s.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.Applicat ion
              > Dim myDb As DAO.Database
              > Dim strDBPath As String
              > Dim RPT As Access.Report
              > Dim blnFound As Boolean
              >
              > Const REPORT_NAME = "MyReport"
              >
              > strDBPath = Application.Cur rentProject.Pat h & "\Mydb.mdb"
              > Set App = New Access.Applicat ion
              >
              > With App
              > .OpenCurrentDat abase strDBPath, True
              > Set myDb = .CurrentDb
              > End With
              >
              > For i = 0 To myDb.Containers (5).Documents.C ount - 1
              > If myDb.Containers (5).Documents(i ).Name = REPORT_NAME Then
              > App.DoCmd.OpenR eport REPORT_NAME, acViewDesign
              > Set RPT = App.Reports(REP ORT_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@com cast.net> wrote in message
              > news:RT%yb.3941 35$Tr4.1148717@ attbi_s03...[color=green]
              > > Thank you, however using:
              > >
              > > Set rpt = MyDB.Containers (5).Documents(0 ).Name
              > >
              > > returns "Type Mis-match"
              > >
              > >
              > > "DFS" <nospamDS@nospa m.com> wrote in message
              > > news:vsoduvghfg fub2@corp.super news.com...[color=darkred]
              > > > Try leaving off the Properties(0).N ame:
              > > >
              > > > Set rpt = MyDB.Containers (5).Documents(i )
              > > >
              > > >
              > > >
              > > >
              > > > "xzzy" <mrbikejoc1@com cast.net> wrote in message
              > > > news:eAWyb.2770 96$9E1.1459853@ attbi_s52...
              > > > > I need to automate a report in a different database.
              > > > >
              > > > > Dim RPT as Report
              > > > >
              > > > > Set MyDB = wrkJet.OpenData base(Applicatio n.CurrentProjec t.Path &
              > > > > "\Mydb.mdb" , True, False)
              > > > >
              > > > > For i = 0 To MyDB.Containers (5).Documents.C ount - 1
              > > > > If MyDB.Containers (5).Documents(i ).Name = "MyReport"[/color][/color][/color]
              Then[color=blue][color=green][color=darkred]
              > > > >
              > > > >
              > > > >
              > > > > 'the following line works
              > > > > DoCmd.OpenRepor t[/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]


              Comment

              Working...