Results 1 to 9 of 9
  1. #1
    Phil H is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2019
    Location
    Phoenix, AZ
    Posts
    19

    Print a report from within a VBA procedure in Print Preview mode

    I'm trying to print a report from within a VBA program. I can't seem to get the syntax right, it always goes directly to the printer. Help says that you can somehow specify Print Preview via the "acView" parameter, but gives no example to follow and I haven't found the secret. I've tried various versions of code:
    Code:
     DoCmd.OpenReport "Rankings"
    w/o the acView at all, this goes directly to printer
    Code:
     DoCmd.OpenReport "Rankings", acViewNormal
    This one sends report directly to printer
    Code:
     DoCmd.OpenReport "Rankings", acView = PrintPreview
    Type mismatch error
    Code:
     DoCmd.OpenReport "Rankings", acViewPrintPreview
    No error, report still goes to the printer.
    I've tried other variations as well, but to no avail.
    I'm running Access 2007, 2016 File Format. Thanks in advance,


    Phil Howard (phil.c.howard@centurylink.net)

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Intellisense popup should give you list of options.

    DoCmd.OpenReport "Rankings", acViewPreview
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    [QUOTE=Phil H;519852
    Phil Howard (phil.c.howard@xxxxxxxxxxxxx.net)[/QUOTE]

    I would not put your email address on any posts. That can get harvested and then you will get spam galore.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Here is what I used to use
    Code:
    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
        'DoCmd.DeleteObject acReport, stParam
    
    
    Exit_cmdShip_Click:
        Exit Sub
    
    
    Err_cmdShip_Click:
        MsgBox Err.Description
        Resume Exit_cmdShip_Click
        
    End Sub
    chkPreview is a checkbox that I used to see report in Print Preview
    Attached Thumbnails Attached Thumbnails Capture.JPG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Phil H is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2019
    Location
    Phoenix, AZ
    Posts
    19
    Quote Originally Posted by Phil H View Post
    I'm trying to print a report from within a VBA program. I can't seem to get the syntax right, it always goes directly to the printer. Help says that you can somehow specify Print Preview via the "acView" parameter, but gives no example to follow and I haven't found the secret. I've tried various versions of code:
    Code:
     DoCmd.OpenReport "Rankings"
    w/o the acView at all, this goes directly to printer
    Code:
     DoCmd.OpenReport "Rankings", acViewNormal
    This one sends report directly to printer
    Code:
     DoCmd.OpenReport "Rankings", acView = PrintPreview
    Type mismatch error
    Code:
     DoCmd.OpenReport "Rankings", acViewPrintPreview
    No error, report still goes to the printer.
    I've tried other variations as well, but to no avail.
    I'm running Access 2007, 2016 File Format. Thanks in advance,
    Phil Howard (phil.c.howard@centurylink.net)

    Response from June7 solved my problem. I want to mark as solved, but can't find the "mark as solved" dropdown. Also, not sure this is the right place to put reply, and I don't understand "use # icon on toolbar when posting code snippets."

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Also, not sure this is the right place to put reply, and I don't understand "use # icon on toolbar when posting code snippets."
    So how did you pust your code within code tags?
    Solved is top right of thread in Thread Tools.
    Attached Thumbnails Attached Thumbnails Solved.JPG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Phil H is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2019
    Location
    Phoenix, AZ
    Posts
    19
    I used
    Code:
    ....my code...
    which I picked up somewhere in Forum instructions, I think.
    Phil H

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Interesting, new to me.

    Can just click # icon on edit toolbar and paste code between tags.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    No, you would have used
    [ c o d e ] and [/ c o d e] without the spaces.

    That is how I normally enter code myself, but for newbies who just pasted a whole block of code into the post and lose all the indentation, the # icon/button is the easier way?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-21-2022, 02:39 AM
  2. Shrinking OLE in print preview mode.
    By LearningAccess in forum Access
    Replies: 3
    Last Post: 03-15-2016, 03:00 PM
  3. Replies: 5
    Last Post: 08-06-2015, 03:26 PM
  4. Replies: 1
    Last Post: 02-21-2015, 11:35 PM
  5. Replies: 6
    Last Post: 03-01-2014, 07:07 AM

Tags for this Thread

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