Results 1 to 6 of 6
  1. #1
    cap10101 is offline Novice
    Windows 7 Access 2002
    Join Date
    Nov 2010
    Posts
    3

    Iterate through records and print report

    Hi
    I have a form and a subform. Each record in the subform has a field indicating the number of times to print a report for that record. I want to be able to print the report for line 1, x number of times... move to line 2 then print x number of times, until EOF. For some reason I just can't seem to get it to work properly. I have started with this code:

    Dim stDocName As String
    Dim printCounter As Integer
    Dim skids As Integer
    Dim rs As Object
    Set rs = Me.Recordset.Clone

    Do While Not rs.EOF
    skids = Forms!frmpackagingdetails.qtySkidsRequired.Value
    printCounter = 1
    Do While printCounter <= skids
    stDocName = "rptSkidTagsAuto"


    DoCmd.OpenReport strDocName
    printCounter = printCounter + 1
    Loop
    rs.MoveNext
    Me.Bookmark = rs.Bookmark
    Loop
    rs.Close
    The print loop is fine if i have only a couple of copies but if I have 50+ copies per line it sends each on individually which is painfully slow. I need to send total copies for each line instead of looping the print. An error also occurs when it reaches the EOF but I dont see why. The error is 3021 no current record but I thought the while not rs.EOF should stop before it tries to move to the next record?
    Any help would be appreciated
    Cheers,
    Kevin

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    An error occurs when it reaches the EOF because you reference rs.bookmark when eof.
    Code:
    rs.MoveNext Me.Bookmark = rs.Bookmark
    Loop rs.Close

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    maybe these codes help?

    DoCmd.OpenReport strDocName, acViewPreview
    DoCmd.SelectObject acReport, strDocName
    DoCmd.PrintOut acSelection, , , , numCopies
    DoCmd.CLOSE acReport, strDocName

  4. #4
    cap10101 is offline Novice
    Windows 7 Access 2002
    Join Date
    Nov 2010
    Posts
    3
    Thanks a lot weekend00! I had already changed my code to what you typed and it worked perfectly. Is there a way to hide the report window from popping up but still keep it the selected object so that the PrintOut method can print it?

    Also, if i dont have the Me.bookmark = rs.Bookmark the code does not proceed, it just repeats the print on the same record instead of advancing. Do I need to place that elsewhere in my code so it works properly or am I missing something else?

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    1 you may try to hide the report or minimize it.


    2 the most directly way is add an if statement:
    Code:
    rs.MoveNext if not rs.eof then Me.Bookmark = rs.Bookmark
    Loop rs.Close

  6. #6
    cap10101 is offline Novice
    Windows 7 Access 2002
    Join Date
    Nov 2010
    Posts
    3
    Haha, so simple. Thanks again weekend00... worked like a charm.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 09-18-2010, 07:52 AM
  2. Print records 3up
    By needafix in forum Reports
    Replies: 5
    Last Post: 08-17-2010, 09:38 AM
  3. Replies: 7
    Last Post: 02-25-2010, 12:32 PM
  4. Print Single Report
    By emkwan in forum Access
    Replies: 1
    Last Post: 01-29-2010, 11:19 AM
  5. Replies: 3
    Last Post: 03-24-2006, 08:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums