Consulting

Results 1 to 6 of 6

Thread: Help with Code

  1. #1

    Help with Code

    Hello,

    I am using Access 365, and we use our database to track nonconforming parts.

    I have a Form that I have the inspectors save and print. Currently I have the default printer set to Print as PDF so they can save to our network location. Once they save, they click CTRL P to select the printer they want to print to.

    My inspectors are older and not very computer savvy. I want them to be able to click the save button to save to file location, then hit a Print button to print to the proper Printer. We only use one Printer to print in our lab.

    The following code is what I have for the save button currently.

    Private Sub Save_Click()On Error GoTo Err_Print_Record_Click
        DoCmd.RunCommand acCmdSelectRecord
        DoCmd.PrintOut acSelection
        Exit_Print_Record_Click:
        Exit Sub
        Err_Print_Record_Click:
        MsgBox Err.Description
        Resume Exit_Print_Record_Click
        End Sub
    How would I modify this code to select the Quality Printer to print, I would use a Print Button for this. or what code do I need to save to a drive location.

    I know it is easier to do all this in a Report, however, when doing this through a report it does not print or save correctly, I have tried several different ways to fix, and the Form is the only thing that works. I did not set up the DB and really don't have time to rebuild a new one

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    371
    Location
    What does "not print or save correctly" mean. What is not correct?

    Instead of depending on default printer setting to save as PDF, use DoCmd.OutputTo method.

    Leave the printer as default and DoCmd.PrintOut form or report.

    Both commands can be behind one button.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Everything is printing and saving correctly. I just wanted to eliminate them having to hit CTRL P to print. They sometimes have to print and save multiple records and they don't understand they have to reset the default. I will try the DoCmd.OutoutTo method.

    Thank you for your time.

  4. #4
    I am trying to get this code to work and can't figure it out. I want it to print to pdf to this file location.

    Private Sub SaveBtn_Click()
        
        DoCmd.OutputTo acCmdSelectRecord, acFormatPDF, "O:\NCMR\InProcess\"
        
    End Sub

  5. #5
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    371
    Location
    Need to include filename in the destination path. What do you want each report to be named? If you don't assign a unique name to each report, it will overwrite existing. Does your current code overwrite? If it does, what is purpose of saving to PDF?

    Where do you get acCmdSelectRecord from? AFAIK, that is not an option with OutputTo.

    Apply filter to form or report if you don't want all records to output.

    Review https://learn.microsoft.com/en-us/of...docmd.outputto

    You said does not work correctly when you use a report - why? Really should use report.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    VBAX Contributor
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    112
    Location
    Create a report.
    Open report with WHERE criteria for the record(s) required.
    Output to pdf is required.

    Private Sub cmdShip_Click()
        On Error GoTo Err_cmdShip_Click
        Dim stRptName As String, stParam As String, stLinkCriteria As String, stDBpath As String, stFTPpath As String, _
        Dim iPreview As Integer, iDialog As Integer, blnPrintIt As Boolean
        stDBpath = CurrentProject.Path & "\"
        stFTPpath = stDBpath & "Gazette\"
        iPreview = acViewPreview
        If Me.ChkPreview Then
           ' iPreview = 2
            iDialog = acWindowNormal
        Else
            iDialog = acHidden
        End If
        stRptName = "Main_by_Ship"
        stParam = Replace(LCase(Me.cboShip.Value), " ", "_")
        stLinkCriteria = "[Ship] = '" & Me.cboShip.Value & "'"
        'DoCmd.CopyObject , stParam, acReport, stRptName
        If Me.ChkPreview Then
            DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
        Else
            DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
            DoCmd.OutputTo acOutputReport, stRptName, acFormatPDF, stFTPpath & stParam & ".pdf", False
            DoCmd.Close acReport, stRptName
        End If
        Exit_cmdShip_Click:
        Exit Sub
        Err_cmdShip_Click:
        MsgBox Err.Description
        Resume Exit_cmdShip_Click
    End Sub

Posting Permissions

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