Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2007
    Posts
    16

    Unanswered: Access 2003 Print Anomaly

    Hi there,

    I have a report in ACC2K3. If the report contains only one page, Access prints it correctly. But if the report contains 2 (or more) pages, then in print preview it seems to be correct (indicating page 1 of 2 or 2 of 2), but when I press the print button, first an empty report comes out which contains only the header and footer and the lower right corner where I placed the page numbers indicates 1 of 37 (or another large number of pages). Then comes the 2 needed pages (with page number 2 of 37 and 3 of 37). Finally the print job stops, no more paper printed.

    Does anybody know how can I correct this behavior?
    OS: Windows XP SP2
    Access ver.: 2003 with SP2

    Thank you in advance!
    Axel

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Axel,

    My guess is the printer driver. I've always had problems with printer drivers and the default printer (ie. control panel), and with MSAccess. For example, I might open a report in preview mode, click on the page setup, set the margins and it prints perfect on the printer connected to my computer but when someone else opens it where they might be using a different printer (or different networked printer), they need to go to page setup, set the margins, and then "save" the report - for some reason they need to click the "save" when previewing the report - then it prints fine for them after that - but if I then open the report, I need to "re-save" the report again after going to page setup for it to print ok on the printer connected to my computer.

    Also note that I've seen it where a "bad" default printer (not really a bad driver but one that Access doesn't like) can cause Access to come up with some errors when trying to debug/compile. I spent days trying to figure out why I couldn't debug/compile error-free only to find that if I changed the default printer on my computer, it worked fine.

    You might try changing the printer driver or default printer and see if that helps with your report or try clicking the "save" when previewing the report and after you do the page setup. Let me know if this helps.
    Last edited by pkstormy; 08-22-07 at 22:30.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Feb 2007
    Posts
    16
    Hello Pkstormy,

    Thank you for the tips. I can try them on the weekend.
    Anyway the strangest thing is that sometimes it prints fine multiple pages, other times number of pages increase. Let me check playing with printer drivers and default printer. I'll keep you informed.

    Thanks!
    Axel

  4. #4
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Quote Originally Posted by Axel123
    Hi there,

    I have a report in ACC2K3. If the report contains only one page, Access prints it correctly. But if the report contains 2 (or more) pages, then in print preview it seems to be correct (indicating page 1 of 2 or 2 of 2), but when I press the print button, first an empty report comes out which contains only the header and footer and the lower right corner where I placed the page numbers indicates 1 of 37 (or another large number of pages). Then comes the 2 needed pages (with page number 2 of 37 and 3 of 37). Finally the print job stops, no more paper printed.

    Does anybody know how can I correct this behavior?
    OS: Windows XP SP2
    Access ver.: 2003 with SP2

    Thank you in advance!
    Axel
    Axel,

    Sounds to me like you have two distinct problems.

    Selecting each section of the report in turn, check the Property Sheet for the Force New Page property. It should read "None" for all sections except the Page Footer section. Caution: not all sections have Force New Page properties. Ignore those that don't for this check. I bet one of the sections is set to either "Before" or "After" for this property.

    Check the source data of the textbox where you store the Page information. "37", or any other spurious number, makes no sense. Something in that data is telling Access to do something idiotic. Do you perhaps try to control it with VBA code that's not working correctly?

    Hope this helps,

    Sam

  5. #5
    Join Date
    Feb 2007
    Posts
    16
    Hello Sam,

    Thank you for your valuable comments.
    I control the page break of the detail section from code, because I want maximum 25 records on one page. After thet I set forcenewpage to yes. Then back to no. I also checked all the other sections which I don'n control from code. All were set to NONE.

    I also saved new margins with no luck. Instead of using default printer, I use now the "USE SPECIFIC PRINTER" option. The only thing changed is that now I see the blank page and the wrong number of total pages in preview too.
    L
    et me describe what is happening.

    I have a 2 sided report. I open it with a button. See code below.
    If I press the button, preview opens and I see a page with no data, just report and group header and footer are shown. Page number indication: 1 of 39. I try to go to the last page. It is 3 of 39 (The blank page + 2 real data pages). I cannot go further.
    ************ NOW COMES THE MAGIC. ******************
    If I go to design view, do nothing just go back to preview, the blank page disappears, page numbers are shown corretly 1 of 2.
    If I print the report now, it still printst the balnk page and the total page number is 39.

    I also tried to save the report in design view and print it. The result is the same.

    I tried this:
    I opened the report directly from the report list. (The referenced form which sets the filter was not open, "[Datum] = Forms![Uzemnap]!Datum")
    The report asked for the date. I gave in the date and tried to print the first page. Page 1 of 2 came out with the correct data. Then I tried to print the second (last) page. Again the wrong setup came alive, the first data page came out as page 2 of 39.

    Any ideas what can be the cause of this?
    Page number line is the following: ="Page " & [Page] & " of " & [Pages]

    Alex

    Report opener Button code:
    Private Sub Szamololap_Click()
    On Error FoTo Err_Szamololap_Click

    Dim stDocName As String

    stDocName = "Szamololap"
    DoCmd.OpenReport stDocName, acPreview
    Reports(stDocName).Filter = "[Datum] = Forms![Uzemnap]!Datum"
    Reports(stDocName).FilterOn = True

    Exit_Szamololap_Click:
    Exit Sub

    Err_Szamololap_Click:
    MsgBox Err.Description
    Resume Exit_Szamololap_Click

    End Sub

  6. #6
    Join Date
    Feb 2007
    Posts
    16
    I did some debugging.
    The source of the report is a query, which does some calculations.
    The number of pages was shown correctly in the wathch window first, but then the code jumped to the module, which does the calculation (I dont know why). I believe, this is the point where the report loses the correct number of pages, because wathc window shows "Out of context" for the PAGES variable. I also realized, that the number of pages shown incorrectly equals to the number of records +1 in the current report.
    Axel

  7. #7
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Axel,

    Try removing these two lines from the Private Sub Szamololap_Click() routine

    Reports(stDocName).Filter = "[Datum] = Forms![Uzemnap]!Datum"
    Reports(stDocName).FilterOn = True

    Instead, put the following two corresponding lines of code into the report's Open() event:

    Code:
    Me.Filter = "[Datum] = Forms![Uzemnap]!Datum"
    Me.FilterOn = True
    Then tell me what happens.

    You can't set the filter after you run the report, only from within the Open() event in the report itself. This isn't your entire problem, of course, but let's solve the little things first.

    Sam

  8. #8
    Join Date
    Feb 2007
    Posts
    16
    Hello Sam,

    Thank you for your correction. I have deleted the filter from button click and placed it to the report open subroutine. But you were right, this wasn't the root cause of the problem.
    Now in print preview the total number of pages is correct, but on the printed page comes again the number of records+1 as the total page number.

    Axel

    Here is the code from the Report:

    Option Compare Database
    Dim forcePBreak As Integer
    Dim nofLines As Integer

    Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
    nofLines = 0
    forcePBreak = False
    Detail.BackColor = conLtGray
    End Sub

    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    If Detail.BackColor = vbWhite Then
    Detail.BackColor = conLtGray
    Else
    Detail.BackColor = vbWhite
    End If
    If Not (IsNull(MLeszallas) And IsNull(MPilota) And IsNull(MotorosGepID)) And (IsNull(MLeszallas) Or IsNull(VFelszallas)) Then
    Detail.BackColor = conYellow
    Else
    If (IsNull(VLeszallas) Or IsNull(VFelszallas)) Then
    Detail.BackColor = conYellow
    End If
    End If
    If PrintCount = 1 Then nofLines = nofLines + 1
    If forcePBreak Then
    Detail.ForceNewPage = 1
    forcePBreak = False
    Else
    Detail.ForceNewPage = 0
    forcePBreak = (nofLines Mod 24 = 0)
    End If
    End Sub

    Private Sub Report_Open(Cancel As Integer)
    If IsLoaded("Uzemnap") Then
    Me.Filter = "[Datum] = Forms![Uzemnap]!Datum"
    Me.FilterOn = True
    Else
    Me.FilterOn = False
    End If
    End Sub

  9. #9
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178

    OMiGosh

    Yiii!!! (Slap hand against head) I just remembered. Sorry I put you thru hell first. The rule: Whenever you limit the number of records on a page programatically, (forcePBreak = (nofLines Mod 24 = 0)) you cannot use the [Pages] built-in function for total pages. Why? Because [Pages] will tell you how many pages Access wants to print out, and doesn't take into consideration the fact that you're limiting it. [Page], which counts individual pages, can still be used, however. So what you need to do is to figure out before running the report how many detail lines will print, divide that number by 24, and call it, perhaps, TotalCalculatedPages. If it has a fraction, round it up. In addition, make an unbound textbox on the page footer section called TotalCalculatedPages. Make sure you set its Visible property to "no". Now you can program your page count text box source as

    Code:
    ="Page " & [Page] & " of " & TotalCalculatedPages
    Sam

    ps You can best figure out the total expected number of lines from within the report itself. The best place to do this, probably, is in VBA in the report's header section, although it depends on certain factors I don't know.

  10. #10
    Join Date
    Feb 2007
    Posts
    16
    Hello Sam,

    Thanks a lot for your advices. I planned to calculate the total number of pages myself as a last chance. I was not aware, that the built-in [Pages] variable cannot be used. Thanks for mentioning it! But it is still strange to me why is it correct in the preview.

    Axel

  11. #11
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    I don't know either, Axel.

    Sam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •