Results 1 to 10 of 10
  1. #1
    jparker1954 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    85

    Unhappy Print ONE record from a form, not all of them

    I have a form in which I put a Print Record button. I assumed that when the user selected one record using the form and press this button that just that one record would print out on the form, not every record in the database. Unfortunately, right now EVERY record prints out. How do I get it to do just the one record the user has selected? Here's the current code for the button:



    Private Sub PrintRecord_Click()
    On Error GoTo Err_PrintRecord_Click

    DoCmd.PrintOut

    Exit_PrintRecord_Click:
    Exit Sub
    Err_PrintRecord_Click:
    MsgBox Err.Description
    Resume Exit_PrintRecord_Click

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Hi
    Have you had a look in the VBA help files? From what I've read there I think this may work but it is untested.
    Code:
    DoCmd.PrintOut acPages, 1, 1
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    I would create a report and then use this technique with OpenReport:

    BaldyWeb wherecondition
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    First filter the form's recordset to the one record.

    Forms are not intended to be printed objects. That is what reports are for.
    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.

  5. #5
    jparker1954 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    85
    Thanks, guess I have a hard time understanding why someone would not want to print one form out if it meets their needs, AND why Access would include a Print Record button in the canned buttons section if it doesn't work. OK, I've vented.

    I'll work on the OpenReport.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Most of us feel you have a lot more control over printing a report than a form, so that's all we print. Basically, forms for interacting with data, reports for presenting it. If the printed form meets your needs, I say go for it, but I'm not sure you can control what record is printed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Having given my 'do as I say, not as I do' advice I will confess that I have situation where I print forms for legacy data. I knew there would be little demand to print this data so went as far as building forms to serve for viewing and printing. The forms are always opened filtered to a single record selected from a search form. pbaldy is correct that it is harder to control the formatted output. I had to carefully size the forms to print on 8.5x11 paper.

    Bob Fitz's suggestion might work to print first record - page 1 as set by the parameters but if user selects 5th record, how will that be translated as a page parameter? Don't know.
    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.

  8. #8
    Access_Blaster is offline User
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2010
    Posts
    339
    Quote Originally Posted by jparker1954 View Post
    I have a form in which I put a Print Record button. I assumed that when the user selected one record using the form and press this button that just that one record would print out on the form, not every record in the database. Unfortunately, right now EVERY record prints out. How do I get it to do just the one record the user has selected? Here's the current code for the button:

    Private Sub PrintRecord_Click()
    On Error GoTo Err_PrintRecord_Click

    DoCmd.PrintOut

    Exit_PrintRecord_Click:
    Exit Sub
    Err_PrintRecord_Click:
    MsgBox Err.Description
    Resume Exit_PrintRecord_Click

    This may help. http://allenbrowne.com/casu-15.html

  9. #9
    mejia.j88 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    california
    Posts
    228
    jparker,
    in case this problem has not been solved:

    this is the code i use to print out labels with information from my form. the labels are constructed as a report and i simply put in w/e fields i want to print out.
    it only prints the current form you are working on.

    pay close attention to the line
    DoCmd.OpenReport "rpt_Dicing_Label", acViewNormal, , "[ID]=" & Me.ID
    as you will have to change the report name; on the form, make sure you have your [ID] field, you cant set it to invisible for aesthetic purposes.


    Private Function PrintLabels()
    Dim Show_Box As Boolean
    Dim Response As Variant
    Dim i As Integer

    ' Set the Show_Dialog variable to True.
    Show_Box = True

    ' Begin While loop.
    While Show_Box = True

    ' Show the input box.
    Response = InputBox("Enter the number of labels to print or press Cancel to skip printing.", "Label Printing", 1)

    ' See if Cancel was pressed.
    If Response = "" Then

    ' If Cancel was pressed,
    ' break out of the loop.
    Show_Box = False
    Else
    ' Test Entry to find out if it is numeric.
    If IsNumeric(Response) = True Then
    For i = 1 To Response
    DoCmd.OpenReport "rpt_Dicing_Label", acViewNormal, , "[ID]=" & Me.ID
    Next i
    Show_Box = False
    Else
    ' If the entry was wrong, show an error message.
    MsgBox "Please Enter Numbers Only"
    End If
    End If
    ' End the While loop.
    Wend
    End Function

  10. #10
    mejia.j88 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    california
    Posts
    228
    one more thing,
    under your "Print Record" button,
    write the code

    Call Printlabels

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

Similar Threads

  1. Replies: 5
    Last Post: 10-26-2011, 02:59 PM
  2. Replies: 10
    Last Post: 11-23-2010, 10:16 PM
  3. Print Single Record
    By stattech in forum Reports
    Replies: 5
    Last Post: 10-05-2010, 03:38 AM
  4. Replies: 6
    Last Post: 07-19-2010, 10:57 AM
  5. Print a specific record report from a form
    By cynthiacorley in forum Reports
    Replies: 27
    Last Post: 02-08-2010, 06:34 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