Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    hnkford is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    4

    Print Report from Current Record

    I am trying to create a command button on a form that prints a report based on the current record's TaskID. below is the code I'm entered:

    Private Sub Cmd75Letter_Click()

    On Error GoTo Err_Cmd75Letter_Click
    Dim stDocName As String
    Dim stWhere As String

    stDocName = "rpt75Letter"
    stWhere = "[TaskID]=" & Me!TaskID

    DoCmd.OpenReport stDocName, acViewPreview, , stWhere
    DoCmd.RunCommand acCmdPrint



    Exit_Cmd75Letter_Click:
    Exit Sub

    Err_Cmd75Letter_Click:
    MsgBox Err.Description
    Resume Exit_Cmd75Letter_Click

    End Sub

    When I click the button I get a message "Run Time Error 3464". When I click debug "DoCmd.OpenReport stDocName, acViewPreview, , stWhere" is highlighted. The TaskID is a text field on the form.

    Please help solve this problem

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    See here for the syntax adjustment required for a text field:

    BaldyWeb wherecondition

    By the way, if you just want to print it, take out acViewPreview and that line alone will print the report; you don't need the next one.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    hnkford is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    4
    I was afraid it was something simple. It was. This line fixed it: stWhere = "TaskID= '" & Me.TaskID & "'"

    Thank you!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help, and welcome to the site!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    SM253 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    6
    I have tried and tried but I am not able to make this Print Report from Current Record feature work. No matter how I write it, I cannot figure out how to get the primary key field to be used in creating the report. I always get the "Enter Parameter Value" dialog box. I do not receive any error messages. The Key is a numeric value, and if I type in the record number I want the report works just fine, but I can't make it work automatically.

  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,521
    Might help to see your code, but the parameter prompt is Access telling you it can't find something, so likely either the field or control name is incorrect.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    SM253 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    Might help to see your code, but the parameter prompt is Access telling you it can't find something, so likely either the field or control name is incorrect.
    This is the code behind the Event Procedure under the Button on the NC Form:

    Private Sub Command55_Click()
    DoCmd.OpenReport "Select_Tag_Report", acViewPreview, , "NCnumber=" & Me.NCnumber
    End Sub


    The Report works fine if you enter the NCnumber you want to see in the dialog box.

    I modified the command to specify acNormal, and even though the print process dialog box pops up, it is followed by the "Enter Parameter Value", box, demanding an NCnumber.


    What does the "Me." signify? I have not come across this before.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Me is a shortcut to refer to the object containing the code, in this case the NC form. If you're getting a prompt, either NCnumber isn't a field in the report being opened, or doesn't exist as a control on that form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    SM253 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    .... or doesn't exist as a control on that form.
    The NCnumber field is the primary key in the data Table, and it is used in the SELECT field for the Record Source. That SQL code is:
    SELECT NC_Internal.NCnumber, NC_Internal.Date, NC_Internal.Department, NC_Internal.OperatorName, NC_Internal.Shift, NC_Internal.PartNumber, NC_Internal.PartName, NC_Internal.Quantity, NC_Internal.JobNumber, NC_Internal.PONumber, NC_Internal.OperationDescription, NC_Internal.Equipmentdescription, NC_Internal.NCType, NC_Internal.NCDescription, NC_Internal.Decision, NC_Internal.Decisiontobedoneby, NC_Internal.Costs, NC_Internal.CostsDetails, NC_Internal.ClosureDate, NC_Internal.Closedby, NC_Internal.[CPArequired?], NC_Internal.CPA, NC_Internal.Comments, NC_Internal.MRBDirection, NC_Internal.MRBMembers
    FROM NC_Internal
    ORDER BY NC_Internal.NCnumber DESC;

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db here (after compacting and zipping)?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    SM253 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    Can you post the db here (after compacting and zipping)?
    Here you go:
    NCM_Sample.zip

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The name of the textbox is "NC Number", not NCNumber. In code because of the inadvisable space try one of these:

    Me.NC_Number
    Me.[NC Number]

    You'd also want to take the criteria out of the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    SM253 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    The name of the textbox is "NC Number", not NCNumber. In code because of the inadvisable space try one of these:

    Me.NC_Number
    Me.[NC Number]

    You'd also want to take the criteria out of the query.
    Odd, I change the Field Name to "NCnumber" yesterday, with no effect. I thought the Name change would cascade automatically, because all of the queries and reports recognized the change.
    I tried both of the fixes you suggested, and neither had any effect. Then I renamed the text box in the form to "NC_Number", changed the Command56 text to DoCmd.OpenReport "Select_Tag_Report", acViewPreview, , "NCnumber = " & Me.NC_Number and the dang thing still doesn't work.

    I then removed the criteria from the Form's Record Source field, and created a qryNC_Number query. No dice.

    The I took out the query criteria altogether, pointing the Form directly at the Table, and it still doesn't work.

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Not sure what's going wrong then. This worked for me:

    DoCmd.OpenReport "Select_Tag_Report", acViewPreview, , "NCnumber=" & Me.[NC Number]

    after taking the criteria out of the report's source query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    SM253 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    6
    Quote Originally Posted by pbaldy View Post
    ..... taking the criteria out of the report's source query.
    Oh That's it! The REPORT's query was in the way. I thought you meant the FORM's query! It works now.

    Thanks for the help!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Email a report of the current record.
    By jonudden in forum Reports
    Replies: 4
    Last Post: 08-21-2023, 07:37 AM
  2. =Report won't Print each record on page
    By ashbear in forum Reports
    Replies: 17
    Last Post: 06-13-2013, 04:04 PM
  3. Report from current record
    By billgyrotech in forum Reports
    Replies: 18
    Last Post: 07-26-2011, 03:39 PM
  4. Show only current record in report from form/subform
    By stelioshania in forum Reports
    Replies: 0
    Last Post: 03-02-2011, 02:19 PM
  5. How to print a single Record's report?
    By yes sir in forum Access
    Replies: 7
    Last Post: 09-20-2010, 07:31 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