Results 1 to 8 of 8
  1. #1
    MJeanBap is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    16

    Another Question on Printing Forms

    I've read some of the previous posts on printing forms, but I still have questions.

    I have 1 form bound to 1 table for data entry and I am looking to print the form. One suggestion mentioned putting a button in the form header to print the report. So it looks as if I will need to create a report, first, since I don't already have one. Is this correct? Is there anything additional I need to do with the report?



    Also, can you provide me the code for printing, please? I have no idea what it entails.

    Super novice.

    Thanks!

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Here is a db that I used to print the form that was open. It actually printed the information that was on the form in a report design. Look at the code behind the command buttons.

    Alan

  3. #3
    MJeanBap is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    16
    It says the expression On Click you entered as the event property produced the following error: invalid outside procedure.

    I used the following code based upon what you gave me (with no success):

    Private Sub Command1_Click()
    End Sub
    Private Sub cmdPrintSubFrm_Click()
    On Error GoTo Err_cmdPrintSubFrm_Click
    Exit_cmdPrintSubFrm_Click:
    Exit Sub
    Err_cmdPrintSubFrm_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrintSubFrm_Click

    End Sub


    Private Sub Detail_Click()
    End Sub

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    You have no command to print a report. You need to include the Docmd line in your code or else access doesn't know what to do. You have not defined your report either.

    Code:
    Private Sub Command28_Click()
    On Error GoTo Err_Command28_Click
        Dim stDocName As String
        stDocName = "Submission"
           DoCmd.OpenReport stDocName, acViewPreview, , "[ID]=Forms!frmClients!ID"
    Exit_Command28_Click:
        Exit Sub
    Err_Command28_Click:
        MsgBox Err.Description
        Resume Exit_Command28_Click
     
    End Sub
    You will also need to make sure that you have a field that identifies the record. In my case it is the field [ID]. My report name is Submission. You will need to change it to yours. This code will print as a report only the record that is open in your form.

  5. #5
    MJeanBap is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    16
    I'm now getting the following message:

    Syntax error (missing operator) in query expression '[ID] = Forms! Reporting Form! ID'.

    My code is as follows:

    Private Sub Command1_Click()
    On Error GoTo Err_Command1_Click
    Dim stDocName As String
    stDocName = "Submission" (I created my own report called Submission like yours)
    DoCmd.OpenReport stDocName, acNormal, , "[ID] = Forms! Reporting Form ! ID"
    DoCmd.OpenReport stDocName, acViewPreview, , "[ID] = Forms! Reporting Form !ID"
    Exit_Command1_Click:
    Exit Sub
    Err_Command1_Click:
    MsgBox Err.Description
    Resume Exit_Command1_Click

    End Sub

  6. #6
    Stingaway is offline Efficiency Junkie
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    The deep south. Keep going until you hit water basically.
    Posts
    224
    You need to remove the spaces and put the Forms information in square brackets like this:

    =[Forms]![Reporting Form]![ID]

    It's not always necessary, but it is always a safety protocol to avoid issues like this...

  7. #7
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Also, you have two DoCmd lines. One will print the record and the other will just show the record. Is this really what you want? Normal prints it. The other one previews it. You should probably comment one of them out by putting a single quote mark (') in front of the line you don't need.

    Alan

  8. #8
    MJeanBap is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    16
    Great! Thank you so much, Alansidman and Stingaway! All of your advice paid off! =)

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

Similar Threads

  1. Question about forms...
    By Kevo in forum Forms
    Replies: 5
    Last Post: 07-13-2011, 09:34 AM
  2. Two Forms on one page"printing"
    By mrkaye in forum Forms
    Replies: 1
    Last Post: 07-09-2011, 12:58 PM
  3. Printing a single Report from two forms
    By cvolkers in forum Programming
    Replies: 4
    Last Post: 03-06-2011, 11:27 PM
  4. Novice question about using established forms
    By runabout6 in forum Access
    Replies: 2
    Last Post: 08-23-2010, 09:00 PM
  5. Replies: 5
    Last Post: 05-24-2010, 11:52 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