Results 1 to 4 of 4
  1. #1
    rob109 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    3

    Printing report causes code to drop out of Do Loop

    I've recently migrated a database from Access 2003 to 2007. I have a piece of code that uses an input box to ask the user how many copies of a report they want printed, I then use a Do While loop to print the required number. The code then carries on the execute the rest of the code. Everything worked fine in '03, but now in '07, after the first copy of the report is printed, the code stops executing completely. In other words, it drops out of the Do While, even though the user asked for multiple copies, and drops out of the Sub completely. If the user presses cancel or enters 0 the code after the print command executes just fine.



    Here's the piece of code :-

    BeepOnce
    varPrintCopies = InputBox(vbCr & vbCr & "How many copies of the Admission Sheet " & vbCr & vbCr & " do you want to print?", strTitle, 1)

    If varPrintCopies = "" Or varPrintCopies = 0 Then
    BeepOnce
    intMsgResponse = MsgBox(" No Admission Sheet will be printed!" & vbCr & vbCr & " Is that OK?", vbYesNo + vbQuestion, strTitle)
    If intMsgResponse = vbNo Then
    GoTo Ask_Again
    Else
    GoTo More
    End If
    Else
    If varPrintCopies <> "" Then
    If Not IsNumeric(varPrintCopies) Or varPrintCopies > 5 Then
    BeepOnce
    MsgBox "Number must be between 1 and 5", vbOKOnly, strTitle
    GoTo Ask_Again
    End If
    Else
    varPrintCopies = 1
    End If

    DoCmd.SetWarnings True

    Do Until varPrintCopies = 0
    intReportFilter = intPatientID
    DoCmd.OpenReport "rptAdmissionSheet", acViewNormal

    varPrintCopies = varPrintCopies - 1
    Loop

    More:
    BeepOnce
    intMsgMorePatients = MsgBox(" The new patient has been added to the database." & vbCr & vbCr & vbLf & " Do you want to add another?", vbYesNo + vbQuestion, strTitle)
    ' Reset the variable telling us if data has been entered in the finders detail
    frmDataEntered = False
    blnDataEntered = False
    End If



    Anyone else come across this and solved it?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Instead of looping, try opening the report in acPreview then using PrintOut method to print however many copies needed:

    DoCmd.OpenReport "rptAdmissionSheet", acViewPreview
    DoCmd.PrintOut acPages, 1, 1, , varPrintCopies
    DoCmd.Close acReport, "rptAdmissionSheet", acSaveNo
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    rob109 is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    3
    Thanks June7 - that works. I just need to fully test it within my app. Have you come across this scenario before - do you think it's a problem with my code or a bug within 2007?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    I do have loop code that batch prints reports (in Access 2007). Even though you are printing the same report, it is opened, printed, closed in each loop so don't understand why not working.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Activating A Drop Down Box Via Code
    By orcinus in forum Programming
    Replies: 2
    Last Post: 08-11-2011, 03:04 PM
  2. General Report question - Drop Down
    By TheProfessorIII in forum Reports
    Replies: 3
    Last Post: 03-25-2011, 09:23 AM
  3. How to loop code to run through entire table
    By kmajors in forum Reports
    Replies: 9
    Last Post: 04-23-2010, 09:27 AM
  4. Looping code for printing reports
    By Lockrin in forum Access
    Replies: 2
    Last Post: 02-09-2010, 05:48 AM
  5. How about creating a drop down menu in a report?
    By beastmaster in forum Access
    Replies: 2
    Last Post: 12-29-2005, 01:01 PM

Tags for this Thread

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