Batch Printing Reports

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Missionary
    New Member
    • Jan 2008
    • 30

    #16
    Originally posted by NeoPa
    I used +"access 2003" +"vba" +"tutorial" and the first few all looked good. I don't want to link directly to any individual link, but that should get you started.

    Have a go through some basics, then come back and we can look at :
    1. Tidying up your understanding of exactly what you want to achieve.
    2. Sorting out what your elemental items are (Objects; Functions; etc).
    3. Putting together an idea of what the code does that you're going to write and how it will link from the elementals to the call.
    Well, I've read through a couple tutorials, and I'm learning, but not quite there yet.

    One thing I've used in the past to "write" vba was to make a Macro in excel or Word and then copy and edit the code. Is there a way to view the VBA equivolent of an access macro? This would help me be more familiar with the basic structure of the code and also learn some commands.

    Comment

    • Missionary
      New Member
      • Jan 2008
      • 30

      #17
      Originally posted by Missionary
      Well, I've read through a couple tutorials, and I'm learning, but not quite there yet.

      One thing I've used in the past to "write" vba was to make a Macro in excel or Word and then copy and edit the code. Is there a way to view the VBA equivolent of an access macro? This would help me be more familiar with the basic structure of the code and also learn some commands.
      Well, I have alot to learn about VBA. I found the following code that was set to print all the reports in a database. I modified it to try and print my report with the different records. So here it is.

      Code:
      Private Sub cmdPrintAll_Click()
       
      
      Dim rst As Recordset
      Dim strSql As String
      Dim stDocName As String
      
      
      strSql = "SELECT tblWards.Ward FROM tblWards;" 
      'This is the field where my values are listed
      
      Set rst = OpenRecordset(strSql) 
      'I don't know what this is, but access doesn't like it
      
      Do While rst.EOF = False
      'Don't know what this is.
      
      Me.Wards = rst
      'Me.Wards is the combo box on my form that the query gets its parameter from.
      
      stDocName = "rptRetentionReport"
      DoCmd.OpenReport stDocName, acNormal
      
      rst.MoveNext
      Loop
      
      End Sub
      I'm getting there I think. But I need your help at this stage.
      Thank you so much for your patience with me.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32662

        #18
        Originally posted by Missionary
        Well, I've read through a couple tutorials, and I'm learning, but not quite there yet.

        One thing I've used in the past to "write" vba was to make a Macro in excel or Word and then copy and edit the code. Is there a way to view the VBA equivolent of an access macro? This would help me be more familiar with the basic structure of the code and also learn some commands.
        I think I must have missed this one when you posted it. Sorry.
        I also used that technique to pick things up in Excel & Word. Very handy, but not so readily available in Access :(
        What you can do for a limited set of tasks is to create things using the relevant wizard, then study the code that's created for you automatically. It's not quiute the same (or as useful) as the Excel/Word technique, but can be of some assistance.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32662

          #19
          Originally posted by NeoPa
          I used +"access 2003" +"vba" +"tutorial" and the first few all looked good. I don't want to link directly to any individual link, but that should get you started.

          Have a go through some basics, then come back and we can look at :
          1. Tidying up your understanding of exactly what you want to achieve.
          2. Sorting out what your elemental items are (Objects; Functions; etc).
          3. Putting together an idea of what the code does that you're going to write and how it will link from the elementals to the call.
          Referring to your latest post (#17), I don't expect we can get anywhere with this unless we look at the items that need to be dealt with. As I said in post #14 (quoted), the first thing we need to look at is a much clearer understanding of your objectives. Otherwise the problem is just as confusing for us as it is for you at the moment.

          We must proceed in order or we are wasting a good deal of time and energy. I could explain what you are (and are not) doing in your code but this would certainly be a very long way around the problem.

          Comment

          • Missionary
            New Member
            • Jan 2008
            • 30

            #20
            Originally posted by NeoPa
            I used +"access 2003" +"vba" +"tutorial" and the first few all looked good. I don't want to link directly to any individual link, but that should get you started.

            Have a go through some basics, then come back and we can look at :
            1. Tidying up your understanding of exactly what you want to achieve.
            2. Sorting out what your elemental items are (Objects; Functions; etc).
            3. Putting together an idea of what the code does that you're going to write and how it will link from the elementals to the call.
            OK, I'll give it a shot:
            1. I have a report that shows the results of a parameter query. I print several reports with different values for the parameter. I print the report from a form. I would like to create a loop that prints a report for each parameter value, taking the values from a table.
            2. The report is called rptRetentionRep ort
            The form that has prints the report is called frmRetentionRpt
            The button on the form that prints the report is called cmdPrintAll
            The combobox (on the same form) that the query looks at to to get the parameter is called cmdPrintAll
            3. The best code I've got so far is on my earlier Post (#17)

            I hope this is clear and covers the basics. Thank you for helping me along.

            Comment

            • Missionary
              New Member
              • Jan 2008
              • 30

              #21
              Ah Hah!! I got it!
              Here it is
              Code:
              Private Sub cmdPrintAll_Click()
              Dim db As DAO.Database
              Dim rst As DAO.Recordset
              Dim strSql As String
              Dim stDocName As String
              Set db = CurrentDb()
              strSql = "SELECT tblWards.Ward FROM tblWards;"
              Set rst = CurrentDb.OpenRecordset(strSql)
              Do While rst.EOF = False
              Me.Wards = rst.Fields("Ward")
              stDocName = "rptRetentionReport"
              DoCmd.OpenReport stDocName, acNormal
              rst.MoveNext
              Loop
              End Sub
              NeoPa,
              Thank you so much for your help! Thank you for not giving up on me, and thanks for forcing me to study it out for myself. My VBA skilz have increased 1000 times.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32662

                #22
                Originally posted by Missionary
                OK, I'll give it a shot:
                1. I have a report that shows the results of a parameter query. I print several reports with different values for the parameter. I print the report from a form. I would like to create a loop that prints a report for each parameter value, taking the values from a table.
                each parameter value
                I assume this comes from some sort of control on your form. Or maybe (as you stated earlier in the thread) you want all of them (We still don't really know what "them" refers to in this context). Can you clarify this point.
                If there is a control that you wish the operator to use to select the parameters, can you give details of the control type, the Row Source, the name and what the MultiSelect property is (if a ListBox).
                taking the values from a table
                Which values are you referring to here?
                Originally posted by Missionary
                2. The report is called rptRetentionRep ort
                The form that has prints the report is called frmRetentionRpt
                The button on the form that prints the report is called cmdPrintAll
                The combobox (on the same form) that the query looks at to to get the parameter is called cmdPrintAll
                ...
                Two controls with the same name? Please try to be more careful - it's confusing enough as it is.
                Are we planning on printing all or just a select few? Where are all the potential parameters stored?

                If, as you say, you are completely new to VBA programming I will need to do more to get you going. Therefore I will need more precise information. You will probably understand by now that precise and correct information is critical at this stage (communicating via posts on a forum). It is a very limiting medium, so imperfect communication can cause more problems than communicating face-to-face.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32662

                  #23
                  Firstly, congratulations !
                  When I started looking at your problem today you hadn't posted #21.

                  The code (amended very slightly for tidiness) seems like it should work. I guess your query (within the report) has a reference built in it to the form control (Wards) rather than being a parameter query as such (Hence setting Me.Wards changes the contents of the report).
                  Code:
                  Private Sub cmdPrintAll_Click()
                    Dim rst As DAO.Recordset
                    Dim strSql As String
                    Dim stDocName As String
                  
                    strSql = "SELECT [Ward] FROM tblWards;"
                    Set rst = CurrentDb.OpenRecordset(strSql)
                    Do Until rst.EOF
                      Me.Wards = rst!Ward
                      stDocName = "rptRetentionReport"
                      DoCmd.OpenReport stDocName, acNormal
                      rst.MoveNext
                    Loop
                  End Sub
                  Personally I would use a filter (See help for DoCmd.OpenRepor t) rather than building the query to assume the form is open and available. If you post the name of the Ward field in the query, I can post the version that would do that for you.

                  PS. Your code allows me to find answers to all the questions I asked before so please ignore them now.

                  Comment

                  Working...