Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Print Preview Correct, output wrong (2002)

    Hi,

    I'm using the following code to print business cards.


    ' Allows one employee to print on entire page

    Const NumberOfCopies = 10
    Static strPreviousName As String
    Static lngCurrentCount As Long
    If Me.Name = strPreviousName Then
    lngCurrentCount = lngCurrentCount + 1
    If lngCurrentCount < NumberOfCopies Then
    Me.NextRecord = False
    End If
    Else
    lngCurrentCount = 1
    strPreviousName = Me.Name
    If NumberOfCopies > 1 Then
    Me.NextRecord = False
    End If
    End If


    When the report opens it shows 10 cards to the page exactly as I need them. When I print them however they only print as one card to the page, not 10 as seen in print preview. I tried printing as a pdf form and the same thing happens. The odd thing is that when I first started using the code (thanks to Hans's help) it worked fine. I'm not sure why now it only prints one to a page vs what is sen in print preview. I've tried it on a variety of printers and its the same on each one. It doesn't seem to be a printer issue.

    Thanks,
    Leesha

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Preview Correct, output wrong (2002)

    Can you post a stripped down copy of the database?

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print Preview Correct, output wrong (2002)

    Sure Hans, here ya go.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Preview Correct, output wrong (2002)

    You must have had it ready for posting! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    The problem only occurs if you print the report from the preview. The static variable lngCurrentCount has already reached NumberOfCopies then, so the code to print the same label is effectively disabled. To work around it, you can use this code:

    Private lngCurrentCount As Long

    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    ' Allows one employee to print on entire page
    Const NumberOfCopies = 10
    lngCurrentCount = lngCurrentCount + 1
    If lngCurrentCount < NumberOfCopies Then
    Me.NextRecord = False
    End If
    End Sub

    Private Sub Report_Page()
    lngCurrentCount = 0
    End Sub

    lngCurrentCount has been made into a module/level variable, and it is reset when a new page is printed.

  5. #5
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print Preview Correct, output wrong (2002)

    LOL! No actually I had stripped it down the other day to take it to the printer who freaked at having to use Access as they don't "know" the program! I assured them that it was fine. Then it blew up! Talk about egg on my face.

    Now for more egg on my face. I read the code and there seems to be two different pieces. I put both in the On Print event of the detail section of the report. The report now opens to show 1 buisness card not 10 and it prints the same way. What am I missing or more accurately, what did I do wrong?

    Thanks,
    Leesha

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Preview Correct, output wrong (2002)

    You should copy the code as posted into the report module, replacing the Detail_Print procedure you had. There is a declaration that should be at the top of the module, immediately below Option Compare Database, there is an On Print event procedure for the Detail section and an On Page event procedure for the report as a whole.

    (I could post the modified database, but I had to change the print settings for the report to make it work on my printer)

  7. #7
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print Preview Correct, output wrong (2002)

    OK, I recopied and it works perfectly. I think I left out the declaration.

    Thanks so much Hans, I really appreciate it.

    Leesha

  8. #8
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Print Preview Correct, output wrong (2002)

    There is an easier way to handle multiple copies per record. Merely create a new table, let's call it tblCopies. This table has one field (name it "Copies" or whatever). Enter at least 10 records, numbering them 1-10 (you can put in as many as you want).

    In the recordsource for your report, merely add tblCopies to the query. You won't link it to any of the other tables, so it creates a Cartesian join. This basically means you get 1 record in the report for each record in tblCopies for each person. Now, if you set a selection criteria on that field "Copies" to <=10, your query will return 10 records for each person. If you have 20 records (numbered 1-20) in tblCopies, you can produce 2 sheets per person merely by changing the selection criteria to <=20. Changing it to =1 gives 1 card per person. No change in code needed at all!
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  9. #9
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print Preview Correct, output wrong (2002)

    Hi Mark,

    Thanks for the tip! It worked like a charm and just save my boss a ton of money. The printer that was going to use the database was going to charge an additional charge due to having to select each name individually. Now all they have to do is hit print!!

    Thanks again,
    Leesha

  10. #10
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Print Preview Correct, output wrong (2002)

    Always nice to save a little money! <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Glad I could help.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  11. #11
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print Preview Correct, output wrong (2002)

    Hi Hans!

    I just had the user call me and say that this code is printing fine in that it is printing 10 business cards per page for the employee name that is chosen from the listbox. However rather than printing 1 page (unless otherwise specified by th user) it is printing 100's of pages. I didn't have any idea what to do with the code to limit it to printing one page of business cards at a time. Is it possible?

    Thanks,
    Leesha

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Preview Correct, output wrong (2002)

    The code does just print one page for me, and there is nothing that would cause printing hundreds of pages. Let the user check the page settings of the report, perhaps the problem will go away if the margins are made slightly smaller.

  13. #13
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print Preview Correct, output wrong (2002)

    Hi Hans,

    Back at this one again. I had them change the page settings but that didn't help and apparently messed up the printing of the business cards. I went on site and sure enough there seems to be an infinite number of pages that print. I'm uploading a stripped down version directly from what they are using. The goal is to have only one page come up.

    Thanks,
    Leesha

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Preview Correct, output wrong (2002)

    If you look back at <post#=489,487>post 489,487</post: >, you'll see that you need to declare lngCurrentCount at the top of the module:

    Private lngCurrentCount As Long

    This declaration is missing from your code. You should have got an error message, but you don't have Option Explicit, so this error passes by unnoticed. <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    BTW, the caption of your form is "EMPOLYEE BUSINESS CARDS".

  15. #15
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print Preview Correct, output wrong (2002)

    Thanks on all counts! I REALLY do try to get the option explicit in on the forms but don't always remember!! Is there a way to universally set it so that its automatically there? I thought I'd seen that somewhere in my reading but that was in the days when I only knew enough to avoid doing anything that was going to give error messages I couldn't figure out!!! Then I found the lounge! <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

    Leesha

Page 1 of 2 12 LastLast

Posting Permissions

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