Creating a Report based on the Current view Form/Subform

G

Guest

I currently have a vehicle movement form for work. The main form lists out
the details (Travel ID, Date, Time, Destination, etc). The subform pulls all
records in the 'Details' table which correspond to the Travel ID (Vehicle
Name, Trailer Towed, Vehicle Order, etc). There is a one-to-many
relationship set up, and the form is working perfectly.
However, the form will be used by some people who have NO IDEA how Access
works. Most of them don't even know that they are using an Access DB!!!
I would like a button at the bottom of the form which will pull a report
showing the main info as well as all associated vehicles.
My goal was to create a report which had the main Travel info, and a
subreport which would list all of the vehicles (associated with the Travel
ID) sorted by vehicle order.
In the end, it would show the Overall travel info as a 'header' type setup,
with a list of vehicles, what they tow, and the passengers.
Can this be done with a single button? I can create the report, but I need
it to blindly pull the current record being viewed with minimal user
interaction.
HELP!!! Please!!!
 
A

Allen Browne

Create the report so that it shows all the travel items.

Then in the event procedure of your command button, use the [Travel ID] in
the WhereCondition of OpenReport, so the report opens filtered to just the
record in your form.

Details and coding example in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
 
G

Guest

Uh oh!
I got it generating the report using the 'generate' button and the code that
you gave me...
However, it's only generating the 'vehicle movement' report for record #1.
It doesn't notice which record I'm looking at at the moment I click
'generate.'
Any ideas?

Here's the copy/pasted code from the onclick event:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'save any edits
Me.Dirty = False
End If

If Me.NewRecord Then 'check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[TDYID] = """ & Me.[TDYID] & """"
DoCmd.OpenReport "Vehicle Movement", acViewPreview, , [TDYID]
End If
End Sub

Allen Browne said:
Create the report so that it shows all the travel items.

Then in the event procedure of your command button, use the [Travel ID] in
the WhereCondition of OpenReport, so the report opens filtered to just the
record in your form.

Details and coding example in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Kim NJ said:
I currently have a vehicle movement form for work. The main form lists out
the details (Travel ID, Date, Time, Destination, etc). The subform pulls
all
records in the 'Details' table which correspond to the Travel ID (Vehicle
Name, Trailer Towed, Vehicle Order, etc). There is a one-to-many
relationship set up, and the form is working perfectly.
However, the form will be used by some people who have NO IDEA how Access
works. Most of them don't even know that they are using an Access DB!!!
I would like a button at the bottom of the form which will pull a report
showing the main info as well as all associated vehicles.
My goal was to create a report which had the main Travel info, and a
subreport which would list all of the vehicles (associated with the Travel
ID) sorted by vehicle order.
In the end, it would show the Overall travel info as a 'header' type
setup,
with a list of vehicles, what they tow, and the passengers.
Can this be done with a single button? I can create the report, but I
need
it to blindly pull the current record being viewed with minimal user
interaction.
HELP!!! Please!!!
 
A

Allen Browne

The 3rd last line should use strWhere for the WhereCondition:
DoCmd.OpenReport "Vehicle Movement", acViewPreview, , strWhere

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Kim NJ said:
Uh oh!
I got it generating the report using the 'generate' button and the code
that
you gave me...
However, it's only generating the 'vehicle movement' report for record #1.
It doesn't notice which record I'm looking at at the moment I click
'generate.'
Any ideas?

Here's the copy/pasted code from the onclick event:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'save any edits
Me.Dirty = False
End If

If Me.NewRecord Then 'check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[TDYID] = """ & Me.[TDYID] & """"
DoCmd.OpenReport "Vehicle Movement", acViewPreview, , [TDYID]
End If
End Sub

Allen Browne said:
Create the report so that it shows all the travel items.

Then in the event procedure of your command button, use the [Travel ID]
in
the WhereCondition of OpenReport, so the report opens filtered to just
the
record in your form.

Details and coding example in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

Kim NJ said:
I currently have a vehicle movement form for work. The main form lists
out
the details (Travel ID, Date, Time, Destination, etc). The subform
pulls
all
records in the 'Details' table which correspond to the Travel ID
(Vehicle
Name, Trailer Towed, Vehicle Order, etc). There is a one-to-many
relationship set up, and the form is working perfectly.
However, the form will be used by some people who have NO IDEA how
Access
works. Most of them don't even know that they are using an Access
DB!!!
I would like a button at the bottom of the form which will pull a
report
showing the main info as well as all associated vehicles.
My goal was to create a report which had the main Travel info, and a
subreport which would list all of the vehicles (associated with the
Travel
ID) sorted by vehicle order.
In the end, it would show the Overall travel info as a 'header' type
setup,
with a list of vehicles, what they tow, and the passengers.
Can this be done with a single button? I can create the report, but I
need
it to blindly pull the current record being viewed with minimal user
interaction.
 

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

Top