Create a receipt as a report for one entry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emandel
    New Member
    • Dec 2006
    • 65

    Create a receipt as a report for one entry

    Hello
    Using MS Access 2003.

    So I have a form where I enter donations which are attached to donors.

    I would like to hit a button on that form that will generate a report which would essentially be a receipt for that donation.

    I need help with the following.
    1) how do I make the report applicable for only that one entry.
    2) How do I attach the button that will take me to that report.

    Please give me the instructions in non-programmer language.

    Thank you,

    eli
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    You would just need to set the WHERE clause when you open the report. For example
    Code:
    DoCmd.OpenReport "your report name",,,"ID = " & ID_Field
    You would need to replace ID with the name of the field that is the primary key field (the field that uniquely identifies that record) and replace ID_Field with the name of the control has holds the primary key value. Just out this code in your Burton's OnClick event.

    Comment

    • emandel
      New Member
      • Dec 2006
      • 65

      #3
      DoCmd.OpenRepor t "your report name",,,"ID = " & ID_Field

      my report is called "Donations"

      The primary key is indeed called id in the table "donations"

      would it then me rewritten as follows?
      DoCmd.OpenRepor t "donations",,," ID = " & ID

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        I would say that it is worth a try. The only question that I have about it is the name of the control on your form whose data source is "ID". There is a really good chance that its name is ID, but not being sure, I'm not sure it will work. Make sure that at the top of your code page, you have OPTION EXPLICIT set and then click Debug>Compile your database name. That should catch a few errors if there are any.

        Comment

        • emandel
          New Member
          • Dec 2006
          • 65

          #5
          Ok correction, the control on the form is donations_id.

          I am not getting the results I want, it is giving me a syntax error. Perhaps the report isn't right. Right now the report gives me all of the records. How do I limit the report to give me just one record, and then how do I get it to open that report to the record I want from the button.

          Comment

          • Seth Schrock
            Recognized Expert Specialist
            • Dec 2010
            • 2965

            #6
            One more question that I forgot to ask. What is the data type of the field ID? If it is a number field, then the syntax would be
            Code:
            DoCmd.OpenReport ReportName:="Donations", WhereCondition:="ID = " & Me.Donations_ID
            If it is a text type, then the syntax is
            Code:
            DoCmd.OpenReport ReportName:="Donations", WhereCondition:="ID = '" & Me.Donations_ID & "'"
            You just need to put the code in your button's OnClick event.

            Comment

            Working...