Open report at last Record

AN60

Registered User.
Local time
Today, 09:38
Joined
Oct 25, 2003
Messages
283
I've been trying to get a report to open up at the last or latest record. Initially I thought all I needed to do was sort the query date field or ID (auto numbers) in descensing order but that doesn't work. The query will sort ok but the report will only open up at the first record. I have a few forms set up to open at the last record so I'm guessing the same can be done with a report. I haven't been able to find anything (searching) which has helped. Any suggestions?
 
If you want a report to show up in the same way as you had the query, go into the SORTING and GROUPING options (View > SORTING and GROUPING).
 
BobLarson
Thanks for your reply. I thought I'd checked & set my Sorting & Grouping preferences but after your suggestion I discovered that I probably hadn't saved my report when I made the original changes. Now it's set & working ok, thank you.;)
 
I have a similiar problem I have a form and want to print or e mail a report that reflects the current record from the form. When I open the report it is in the first record of the table the form is based upon. Any other ideas?
 
If you are saying that you want the report to only include the form's current record, then you need to use the Where argument of the OpenReport Method. Also, don't forget to save the current record before opening the form.

Code:
If Me.Dirty Then
    DoCmd.RunCommand acCmdSaveRecord
End If

DoCmd.OpenReport "ReportName", acViewPreview, , "MyID= " & Me.MyId
 
Another method, which appears to be more complicated, is to pass Me as a pointer through OpenArgs.

At the receiving end, Me.Recordset can be used to reference the current record.

A direct call back to the current record can be made with an example line like this:-
GetObjectFromPointer(Me.OpenArgs).Recordset!CompanyName

A demo is available in the SkyDrive link in my signature under the directory name of 'OpenArgs Current Record'.
The demo passes to a Form but it is also applicable to Reports.

It appears to be complicated but it opens up a whole new world in passing read/write arguments through OpenArgs.

Chris.
 
Another method is to pass a pointer to the Form, through OpenArgs to the Report, and get the current Filter and Sort Order of the Form in Datasheet view. More flexible because you can filter up/down to the requirement with a sorted list.

Sample A2003 demo attached.

Chris.
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom