Results 1 to 3 of 3
  1. #1
    Waterdog's Avatar
    Waterdog is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Colorado
    Posts
    22

    Printing a report from a form

    Hey all, need some input on coding for a form. Years ago I had developed some stuff in Access for handling some different tasks at work. Well, that stuff doesn't work quite as well anymore. Hurray for non backwards compatibility. I've decided to dive into redeveloping things, start fresh as it were. One of the tasks that my database handles is processing incoming product returns. I've got a form that contains customer info and basic shipping info and such. In the details portion of the form I have a subform where the actual products are entered in for the product returns. Once information is entered in, for the old system I'd click a button and it would load a report that displayed this information. I'm trying to recreate this now in Access 2010. Pretty sure I developed all this originally with Office XP. Yeah, old stuff. Anyway, I'm finding with Access 2010 that I can embed a macro as the action on clicking the button on my form. Seems to be a nifty, simpler version of just straight coding. The issue I have is that when I click on the button to print, whether it just prints or I get the print preview of the report, I want it to only pull the info from that current record including the products associated just with that current record. And as such currently it'll list products but it repeats all items, not just those for the current record. Below is the coding that I had for the original version of my database from a decade plus ago:

    Private Sub cmdPrintRecord_Click()

    On Error GoTo Err_Handler
    DoCmd.RunCommand acCmdSaveRecord

    Dim strReportName As String
    Dim strCriteria As String

    strReportName = "Printable_Returns_Form_rpt"
    strCriteria = "[Return Number]=" & Me![Return Number]
    DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

    Exit_This_Sub:
    Exit Sub
    Err_Handler:
    If Err = 2501 Then
    Else
    MsgBox "Error# " & Err.Number & "" & Err.Description
    End If
    Resume Exit_This_Sub

    End Sub

    The field [Return Number] was the primary key field for the main return table and is what I used as the foreign key for the table containing the list of products returned for that particular entry. This coding allowed for clicking the button and bringing up a print preview of the report that would display this information. Can someone do one of a couple things. Either give me some suggestions on what I should be putting in for criteria in the embedded macro for this type of thing or otherwise help me to better understand how to modify this code so that instead of previewing the report, it just straight tells the computer to send that report straight to the printer. Both options would be nice as initially I'd like to see the preview to make sure formatting is good and all but eventually set up the database to where it just prints it.

    Along with that I'd love to see input on how I could also possibly go with a third option of "printing" the report straight to a PDF file. Holler back if you have any questions for me or need any further info on this project. It's been years since I dove head first into Access. Been taking some doing to learn where things are and what some of the settings do again, especially with changes in version of the program over the years. And I haven't done much coding in a while but fire away. Gives me a good crash course in refreshing my memory on programming. Thanks in advance!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Remove the acViewPreview parameter:

    DoCmd.OpenReport strReportName, , , strCriteria

    Explore the OutputTo method for saving as PDF.
    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
    Waterdog's Avatar
    Waterdog is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Colorado
    Posts
    22
    Thanks June7! Just tried the suggestion for just straight printing and that appears to work great. I'll have to mess around with the file saving options, see what I can pull off. Appreciate the help!

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

Similar Threads

  1. Printing a report from form in view
    By keiath in forum Reports
    Replies: 24
    Last Post: 04-04-2014, 09:26 AM
  2. Printing report from Form
    By cotri in forum Access
    Replies: 8
    Last Post: 05-24-2013, 12:01 PM
  3. Printing a report in a navigation form
    By DanKoz in forum Forms
    Replies: 2
    Last Post: 08-29-2011, 12:11 PM
  4. Printing a single report from form
    By OFA in forum Forms
    Replies: 9
    Last Post: 06-08-2010, 09:27 AM
  5. Replies: 16
    Last Post: 06-03-2009, 07:01 AM

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