Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    balderman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55

    Printing Help! Is printing more than one record every once in a while...


    Someone in this group helped me with the code in a button to print a report and print only one record...it works most of the time but all of a sudden now, when the print dialog comes up that says "Printing 1 page...." It will start counting up and says it is going to print more than one page and we have to cancel it, close out the database and open it back up to get it to print only one record. It is doing this even though in the print preview there is only one record showing and it is filtered to show only one record. Does anyone know what is causing this and how to fix it???

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    What is the code and how is it called?

  3. #3
    balderman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    Quote Originally Posted by Minty View Post
    What is the code and how is it called?
    Private Sub GenerateWorkOrder_Click()
    Dim sWhere As String
    Dim iMyID As Long

    'tblWorkOrder Subform

    iMyID = Me.[tblWorkOrder Subform]![Work Order No]
    sWhere = "[Work Order No] = " & iMyID

    DoCmd.OpenReport "rptWorkOrder", acViewPreview, , sWhere

    End Sub

    Private Sub TabCtl52_Click()

    End Sub

    What do you mean, how is it called? It is a button on a form that is clicked to bring up the report in print preview and then they click the print button from there.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Okay - that is nice and simple.
    I assume that there is always a valid value in your subform work order field ?

    The report can't be opened anywhere else by any chance can it ?
    If it was already opened, unfiltered then the code would not reopen or refresh it.

  5. #5
    balderman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    No, the button is the only way we run the report and me and one other person has used it so far and we do not both run the database at the same time. It was working perfectly and then once I added some customer data into the database and we started using it, it would start doing that. And it doesn't happen every time, just every once in a while.

    And yes there is always a valid work order number because it's an autonumber and numbers the work order every time we create a new one

  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    That sounds very odd. It may have something to do with the ID being on a sub form.

    Add a the code in red below and next time it plays up open the vba code window (Press Alt+F11) ,
    then look in the immediate window (Press Ctrl+G) to see what it thinks sWhere was at the time.

    Code:
    Private Sub GenerateWorkOrder_Click()
    Dim sWhere As String
    Dim iMyID As Long
    
    'tblWorkOrder Subform
    
    iMyID = Me.[tblWorkOrder Subform]![Work Order No]
    sWhere = "[Work Order No] = " & iMyID
    
    Debug.Print sWhere
    DoCmd.OpenReport "rptWorkOrder", acViewPreview, , sWhere
    
    End Sub

  7. #7
    balderman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    ok, thank you!

  8. #8
    balderman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    Ok I did what you said above and this is what I got....To me that means that it is going to only one record like it is supposed to, so why is it that the print pop-up box will saying printing page 1...2..3..4..5..and so on and keep going unless I hit cancel?
    Click image for larger version. 

Name:	screenshot.jpg 
Views:	23 
Size:	90.4 KB 
ID:	31877

  9. #9
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    That might just be the way the printer is set up, maybe it only prints one page after all that! Use something like PdfCreator and see how many pages print.

    You can also try filtering the report using the record source instead. In the query for the record source, put the [Work Order No] criteria to =Forms!frmCustomer![tblWorkOrder subfrm]![Work Order No].

    (PS Spaces in field names is very bad!)

  10. #10
    balderman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    Quote Originally Posted by aytee111 View Post
    You can also try filtering the report using the record source instead. In the query for the record source, put the [Work Order No] criteria to =Forms!frmCustomer![tblWorkOrder subfrm]![Work Order No].
    If I do this, will it effect the coding behind the button?

  11. #11
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Yes - you will open the report without a filter.

  12. #12
    balderman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    OK, I did this and it is still happening....must be a printer issue then...I am gonna do some googling on that. Thanks for the help! It's just a PITA to have to close out of it all, open it back up, search for the customer and try to reprint after every time we do a work order....hopefully I can find a solution

  13. #13
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Can you print directly from the form, or do you have to go thru preview first? Worth a try.

  14. #14
    balderman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    Well that is how the button is set up, to go to print preview, and I didn't do it someone did it for me so IDK how to change it and I am afraid to mess with it and mess the whole thing up

  15. #15
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Change the command to
    DoCmd.OpenReport "..",acPrint (or something like that, VBA will provide the correct syntax)
    That will print directly to the printer without first going thru print preview.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Printing of separate record
    By Erictsang in forum Forms
    Replies: 5
    Last Post: 11-12-2017, 11:25 PM
  2. Printing to PDF (only need 1 record)
    By lccrews in forum Forms
    Replies: 1
    Last Post: 08-25-2017, 12:20 PM
  3. Printing specific record
    By mike23 in forum Forms
    Replies: 5
    Last Post: 04-05-2014, 08:41 AM
  4. Replies: 0
    Last Post: 05-25-2011, 06:13 AM
  5. Printing the active record only
    By aligahk06 in forum Access
    Replies: 3
    Last Post: 12-02-2010, 08:22 PM

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