Building a report for current record

  • Thread starter Thread starter |PiP|
  • Start date Start date
P

|PiP|

I'm new to Access and want to know if its possible to build a report
based on the current record that is being displayed in a form.

(Ie, I have made a "completed orders" form which show the information of
each of my completed orders, and I want to put a command button in the
form that says "Create Invoice" which takes all the information from the
current record ONLY and puts it into a report I have designed. Is this
possible? Btw, can anyone recommend a really good MS Access book? I am
not afraid of programming (I program in Java, Python and PHP), but need
to learn VB and VB for Applications. Thanks :D
 
|PiP|

There are two, closely related, ways that this is commonly done.

First idea is to reference the form's current record, via its primary
key field, in the query that the report is based on. So, maybe you have
an OrderNumber field or some such. So in the query that the report is
based on, in the Criteria of the OrderNumber column, you would put the
equivalent of this...
[Forms]![Completed Orders]![OrderNumber]

Second idea is to use the Where Condition argument of an OpenReport
macro action, or of an OpenReport method in VBA, to specify the record.
For example, your code on the Click event of the command button might
look like this...
DoCmd.OpenReport "YourReport", , , "[OrderNumber]=" & Me.OrderNumber

As regards reading, I recommend "Building Access Applications" by John
Viescas.
 
Steve said:
|PiP|

There are two, closely related, ways that this is commonly done.

First idea is to reference the form's current record, via its primary
key field, in the query that the report is based on. So, maybe you have
an OrderNumber field or some such. So in the query that the report is
based on, in the Criteria of the OrderNumber column, you would put the
equivalent of this...
[Forms]![Completed Orders]![OrderNumber]

Second idea is to use the Where Condition argument of an OpenReport
macro action, or of an OpenReport method in VBA, to specify the record.
For example, your code on the Click event of the command button might
look like this...
DoCmd.OpenReport "YourReport", , , "[OrderNumber]=" & Me.OrderNumber

As regards reading, I recommend "Building Access Applications" by John
Viescas.


I understand the second method (in terms of logic, not sure how to
implement it). But the first method looks easier.
What is the ! for?
 
Steve said:
|PiP|

There are two, closely related, ways that this is commonly done.

First idea is to reference the form's current record, via its primary
key field, in the query that the report is based on. So, maybe you have
an OrderNumber field or some such. So in the query that the report is
based on, in the Criteria of the OrderNumber column, you would put the
equivalent of this...
[Forms]![Completed Orders]![OrderNumber]

Second idea is to use the Where Condition argument of an OpenReport
macro action, or of an OpenReport method in VBA, to specify the record.
For example, your code on the Click event of the command button might
look like this...
DoCmd.OpenReport "YourReport", , , "[OrderNumber]=" & Me.OrderNumber

As regards reading, I recommend "Building Access Applications" by John
Viescas.

I have tried the first method. However, when I click my command button,
it says "Enter Parameter Value".

What be wrong? My table with my orders is called Orders, with its
primary key orderNo

So I put in the Criteria of orderNo of the query my report is based on
[Forms]![Orders]![orderNo]

Do I leave [Forms] as [Forms]?

Also, in my Orders table, I simply specify completed orders with a
field, called completed that has y for completed, n for not completed.
 
|PiP|

Is 'Orders' the name of the form? That's what you are telling the
query... "select the record from the table where the value of the
OrderNo field is the same as the value of the OrderNo field in the
current record on the Orders form". If you get a 'Enter Parameter
Value' prompt, it would indicate that the query can't evaluate the
expression [Forms]![Orders]![orderNo], which most commonly indicates
that the form is not named 'Orders' or that the Orders form is not open
at the time, or that there is no field named OrderNo on the form. I
thought you indicated in your initial question that the form is named
"completed orders".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top