print current report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jawbone
    New Member
    • Nov 2011
    • 14

    print current report

    hello educated friends

    i have a question. i created a table name info. the primary key field is [maininfoID], i created a query from that table named it [info query], and a form from that query. On my form which by the way named [timesheet]i want my employees to enter data,then press the print button to print out a current report of the information that was just entered. report name is [yourcopy] i was told to use this event procedure
    Code:
    DoCmd.OpenReport "rptyourcopy",acViewPreview, , _
    "[maininfoID]=Forms!frmtimesheet"
    i know theres more to this, can someone help me please.
    Last edited by Stewart Ross; Dec 29 '11, 07:20 PM. Reason: Added code tags
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    It is essential that you understand what the code is doing - being 'given it' is not enough. The OpenReport action can be filtered so that instead of the report showing all records it shows just a subset of them, or in this case, the record matching the one in your form.

    To do this the MainInfoID field on the report has to be matched to the corresponding value on your form - but at present (in line 2 above) you are not supplying the value of the field at all, just a reference to the form itself. You also need to include the value of the control, not a reference to its name, in the filter statement.

    Assuming that the control on your form is also called maininfoID, try replacing line 2 with:

    Code:
    "[maininfoID] = " & Forms!frmtimesheet!maininfoID
    or, using the simpler reference to the current form itself available using the Me keyword,

    Code:
    "[maininfoID] = " & Me!maininfoID
    This assumes that your primary key is a number. If it is not a number but is instead a text string, you would need to include the value inside single quotes, like this:

    Code:
    "[maininfoID] = '" & Me!maininfoID & "'"
    Please note that this last example is for text strings only - it will not work at all if the value being matched is a number, so please do not confuse the two forms of the statement!

    -Stewart
    Last edited by Stewart Ross; Dec 29 '11, 07:34 PM.

    Comment

    • jawbone
      New Member
      • Nov 2011
      • 14

      #3
      ok Mr Ross
      Code:
      Private Sub Command151_Click()
      Dim strReport As String
      Dim strWhere As String
      
      strReport = "info"
      strWhere = "[maininfoID] = """ & Me![maininfoID] & """"
      
      DoCmd.OpenReport strReport, acViewPreview, , strWhere
      
      End Sub
      im getting a run-time error 2103, :the report name you entered incorrect but i know its correct the name is [yourcopy]
      Last edited by Stewart Ross; Dec 29 '11, 08:43 PM. Reason: Added code tags

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        The error message is pointing out the obvious - read your last post. Why have you got this line?

        strReport = "info"

        Info is NOT the correct name of your report, which you have said yourself is yourcopy. That line should surely be

        strReport = "yourcopy"

        or, if that too is incorrect and it is really what you posted in post #1,

        strReport = "rptyourcop y"

        You have to be consistent and correct in what you post!!

        -Stewart
        Last edited by Stewart Ross; Dec 29 '11, 08:42 PM.

        Comment

        Working...