Home End User
New Blog Posts: Merging Reports - Part 1 and Part 2

How to load reports in code

edited May 2006 in End User
Hi,

THIS: How to Programmatically Load Reports that were Saved
using the Report Explorer

I cannot get this to work according to your instructions.

This is what I added: (I added the getReport function to locate the
record.)..

function TmyEndUserSolution.ReportLocateRecordEvent(Sender: TObject; const
aReportName: String): Boolean;
var FFolderid: string;
begin

{add logic here to locate the record and return True if it is found}
FFolderid := 'Production Reports';
Result := getReport(FFolderid, aReportname);

end;
function TmyEndUserSolution.getReport(FolderName: string; theReportName:
string): Boolean;
begin
tblFolder.First;
tblItem.First;
if tblFolder.Locate('Name', 'Production Reports',[locaseinsensitive])
then
begin
if tblItem.Locate('Name', TheReportname,[locaseinsensitive]) then
result := true
else
showmessage('Could not locate ' + TheReportName);
end
else
showmessage('Could not locate ' + foldername);

end;


What happens is if I have more than one Folder in the report Explorer, and
go to a different folder and open a report in there and then close the
report, then I close the Report Explorer and try calling the report with
code, I get this error: "Record not found: Pictures Production".

Here is the code I am using to call the report from the "Production Reports"
folder:

MyReport.DataPipeline := dm1.person_db;
myreport.Template.DatabaseSettings.name :=
'Pictures Production';
myreport.Template.LoadFromDatabase;
myreport.Print;


Any ideas on how to load reports from code even if you navigate to other
folders in Report Explorer first?

THANKS!!!
pl




This is the article:

Comments

  • edited May 2006

    - The tblFolder.Locate is not going to help.

    - The tblItem.Locate should work by itself, as long you do not have two
    items with the same name stored in different folders. I do not know why that
    locate would be failing.

    - To load a report what is required is the FolderId and ReportName. These
    are both tblItem fields. So your first locate on tblFolder could be used to
    get the FolderId that can be used to perform a locate on the tblItem.

    - One solution is to call myReportExplorer.LoadReport(myReportName,
    myFolderId) and let it load the report for you.

    - if you want to implement your own Locate code I would look at the
    ppRptExp.pas, the methods LoadReport, ReportLocateRecordEvent, and
    LocateItemRecord




    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited May 2006
    Hi Nard,
    Thank you for help.
    I have it working now.
    I do a locate on the tblFolder for the Folder name and get the FolderID.
    Then I save it to a variable called "myFolderID".

    To call the report, I use this:
    ppReportExplorer1.LoadReport('Favorites_By_Food
    Production',myFolderID);
    myreport.Print;

    This works.
    Thanks for you help.


This discussion has been closed.