Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2012
    Posts
    126

    Unanswered: VBA- Print to tray two is not working.

    I created the code below to open an append query that appends new records. Then a report is opened showing just the results. I have it selecting a certain printer and then printing to tray two. When I compile there are no errors but when I run it I get error "the number you used to refer to the report is invalid".

    Code:
    Private Sub cmdPrintIRTags_Click()
    On Error GoTo Err_cmdPrintIRTags_Click
    'Message box confirming update
    If MsgBox("Inventory Reduction Update?", vbYesNo, "DSW Inventory Reduction") = vbYes Then
    'turn off warnings
    DoCmd.SetWarnings (warningsfalse)
    'run an update query
    DoCmd.OpenQuery "qryDSWInventoryReductionUpdate"
    'open the report that views the data from the update query
    DoCmd.OpenReport "rptInventoryReductionSignsNew", acWindowNormal
    
    If Application.Printer.DeviceName Like "*HP LJ300-400*" Then
        'Set the report destination paper bin to Tray 2
        'Use number not name, cannot exceed 250
        Reports(rptInventoryReductionSignsNew).Printer.PaperBin = 2
    End If
    DoCmd.PrintOut acPrintAll
    DoCmd.Close acReport, rptInventoryReductionSignsNew, acSaveNo
    
    DoCmd.SetWarnings (warningson)
    Else
        End If
        
    Exit_cmdPrintIRTags_Click:
        Exit Sub
    Err_cmdPrintIRTags_Click:
        MsgBox Err.Description
        Resume Exit_cmdPrintIRTags_Click
    
    End Sub
    The code for the printer section I found doing a google search and it works on another button without the msgbox.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    put a watch n the code and step through it
    see if there is something not being set tot he values you expect

    I'd be suspicious of the printer paper bin if the the printer cannot support it
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Aug 2012
    Posts
    126
    its highlighting

    Code:
    If Application.Printer.DeviceName Like "*HP LJ300-400*" Then
    I do have it working in another button, heres the code for it.

    Code:
    Private Sub CmdPrintAllShelfTags_Click()
    On Error GoTo Err_CmdPrintAllShelfTags_Click
    
    
    'open report in preview mode because is only way to change bin and/or printer destinations
    DoCmd.OpenReport "rptShelfTags", acPreview, acWindowNormal
    If Application.Printer.DeviceName Like "*HP LJ300-400*" Then
        'Set the report destination paper bin to Tray 2
        'Use number not name, cannot exceed 250
        Reports(rptShelfTags).Printer.PaperBin = 2
    End If
    DoCmd.PrintOut acPrintAll
    DoCmd.Close
    
    Exit_CmdPrintAllShelfTags_Click:
        Exit Sub
    Err_CmdPrintAllShelfTags_Click:
        MsgBox Err.Description
        Resume Exit_CmdPrintAllShelfTags_Click
    End Sub
    Since the printer that its printing two will always be used for this application should I use
    Code:
     Set Application.Printer = Application.Printers("Printer Name")
    If so where would I used it? As a public sub and call to it from my private sub?
    Last edited by Syrch; 10-12-12 at 13:53.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    So what value do you get for
    Application.Printer.DeviceName
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Aug 2012
    Posts
    126
    Quote Originally Posted by healdem View Post
    So what value do you get for
    Application.Printer.DeviceName
    I feel like a rookie on this one. Im not sure how to use the string and see the value it returns. I put it on a forms on load action and nothing came up.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you re developing in Access then you need to get to grips with the debugging tools available to you.
    you can place watches on code,
    set breakpoints then step through code
    you can alter values at runtime to make certain the code is sane
    you can fix something then rerun the same code
    you can evaluate vba expressions on the fly

    it may take a couple of hours to fully bone up on it, but if you are doing anything in Access, apart from schoolwork then its well worth paying that price.
    https://www.google.co.uk/#hl=en&scli...w=1920&bih=993
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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