Question Generate report from data just entered in a form (1 Viewer)

carrybag93

Registered User.
Local time
Today, 19:40
Joined
May 24, 2012
Messages
73
Hello,

I was wondering if there is a way to generate a report (maybe through use of a macro or something) from the data you just entered in a form.

So, there is an order form and the user fills out their details, saves the order, and then they can press a 'Generate Receipt' button, and a report pops up that is printable. Is this possible?

Thanks!
 

carrybag93

Registered User.
Local time
Today, 19:40
Joined
May 24, 2012
Messages
73
Could you please explain what it means?
 

carrybag93

Registered User.
Local time
Today, 19:40
Joined
May 24, 2012
Messages
73
I'm sure it makes sense, I just have no experience with Access (with exception for the last couple of weeks), so I am unfamiliar with the terms it uses and how to adapt the code for use in my own database, and where to put it. Does the code you linked me to generate a new report, or does it just add data to a previously made one? I need one generated for each sale, which can then be saved, printed and emailed by the user.
 

Isskint

Slowly Developing
Local time
Today, 10:40
Joined
Apr 25, 2012
Messages
1,302
The way i would approach this is as follows:

  1. Set the forms Cycle property to Current Record (Properties>>Other)
  2. Place a control on the form to Print the report.
  3. Code the controls ONClick event as follows:
    1. DoCmd.RunCommand acCmdSaveRecord
      DoCmd.OpenReport "ReportName", acNormal, , "([OrderID])=" & Me.[OrderID]
 

carrybag93

Registered User.
Local time
Today, 19:40
Joined
May 24, 2012
Messages
73
I made a print button and added the code like you said, but this error came up. What did I do wrong? I also changed the cycle to This Record. Was I supposed to change DoCmd to something else?
 

Attachments

  • error.png
    error.png
    88.8 KB · Views: 149

carrybag93

Registered User.
Local time
Today, 19:40
Joined
May 24, 2012
Messages
73
Thanks :)

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acNormal, , "([OrderID])=" & Me.[OrderID]

That's the code I put on the print button's event OnClick. Am I supposed to have a report already made for this to work, and replace "ReportName" with the name of the report? Because the whole point of this is to generate a NEW report, not open one that was already made. Am I supposed to change anything else in the code for it to work?

This is the last little part of my whole project, so I'm kind of keen on getting it done :)

Thanks for all your help (both of you) so far!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:40
Joined
Aug 30, 2003
Messages
36,124
Yes, you're supposed to have a report built. Creating a new report on the fly would be highly unusual and no easy feat.
 

carrybag93

Registered User.
Local time
Today, 19:40
Joined
May 24, 2012
Messages
73
And I put the name of the report in "ReportName"? Does the data in the report change when you press the button? Thanks for your help. I must be very frustrating!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:40
Joined
Aug 30, 2003
Messages
36,124
You create a report that displays all records. The code will restrict it to the displayed record when it opens.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:40
Joined
Aug 30, 2003
Messages
36,124
Is this a trick question? The table has one more record in it. If you mean with the report, it will show any record in the table.
 

carrybag93

Registered User.
Local time
Today, 19:40
Joined
May 24, 2012
Messages
73
But I'll make the report with the records already created, and then when a new order is made in the order table, and they press the receipt button, a report will pop up with a whole heap of records that don't even include their order.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:40
Joined
Aug 30, 2003
Messages
36,124
The wherecondition argument ("[OrderID]=" & Me.[OrderID]) restricts the report to the OrderID displayed on the form.
 

Isskint

Slowly Developing
Local time
Today, 10:40
Joined
Apr 25, 2012
Messages
1,302
A report is just a set of instructions on where to get the data from and how to present it. Each time you open a report it is based on the most uptodate data in the table. So when your customer has entered their order and presses the Print button, the VBA will save that record and then call the report restricitng the records the report calls to just the last one created.
 

carrybag93

Registered User.
Local time
Today, 19:40
Joined
May 24, 2012
Messages
73
Thanks! Is there a way to allow the user to press a button to see the report instead of just printing it? And then on the report is the button to print and email the report? Is there a way of saving the new report, or does it count as the same old one because it's just been restricted?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:40
Joined
Aug 30, 2003
Messages
36,124
If you look in VBA help at OpenReport, you'll see the argument that controls that.
 

Isskint

Slowly Developing
Local time
Today, 10:40
Joined
Apr 25, 2012
Messages
1,302
VBA help can be accessed by pressing F1, when in the Visual Basic editor (thats the screen where you type in all the coding).

An argument (or parameter) is the information or settings you provide a command to enable it to work. So for OpenReport you have[FONT=&quot]:

OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)[/FONT]

Now normally you can ignore most of these as ReportName is the only argument you need to supply.

In your case - DoCmd.OpenReport "ReportName", acNormal, , "([OrderID])=" & Me.[OrderID] - just replace the acNormal with acPreview.
 

Users who are viewing this thread

Top Bottom