Situation: open an MSACCESS report, output to PDF and download, using PHP:
1 - Initially I used the following approach that worked on my computer:
try {
// Create a COM object for Access Application
$accessApp = new COM("Access.Application") or die("Unable to instantiate Access");
// Open the database
$accessApp->OpenCurrentDatabase($databasePath);
// Open the report
$accessApp->DoCmd->OpenReport($reportName, 5, null,$filtro);
// Set the output file path
$outputFilePath = 'D:\\xampp\\htdocs\\sagesp\\reports\\PCT_'.$turma.'.pdf';
// Export the report to PDF
$accessApp->DoCmd->OutputTo(3,$reportName,"PDF Format (*.pdf)", $outputFilePath, false);
$accessApp->Quit();
unset($accessApp);
...
When I put it into production, Windows Server R2 2008, Office 2010. My PC is Win10, Office2019, the reports produced on Win Server did not fit on the page. Everything worked fine on my PC.
2 - Second approach, I tried this, i thought it controlled better and it was impossible not to work (how wrong I was :( )
VBA Function, works well in both Access (I tested)
Public Function ExportReportToPDF(ByVal reportName As String, ByVal filtro As String, ByVal turma As String)
DoCmd.OpenReport reportName, acViewReport, , filtro, acHidden
DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, "D:\xampp\htdocs\sagesp\reports\PCT_" & turma & ".pdf", False
End Function
PHP
$turma=$_GET['turma'];
$rpt=$_GET['rpt'];
$databasePath = 'D:\xampp\htdocs\sagesp\SAGESP-2023-24-AEPA.mdb';
$reportName=$rpt;
$filtro='turma="'.$turma.'"';
$accessApp = new COM($databasePath) or die("Unable to instantiate Access");
$result = $accessApp->Application->Run("ExportReportToPDF",$reportName,$filtro,$turma);
Once again, it works 100% on my PC, but it doesn't work at all on Win Server, tested with localhost and remote. The database on my PC is a copy of the one on the Win Server, my Office is 2019 and the other is 2010 and the OS is different, both have the extension=php_com_dotnet.dll in php.ini I have the following error in the console: 'error:%20%3Cb%3ESource:%3C/b%3E%20Unknown%3Cbr/%3E%3Cb%3EDescription:%3C/b%3E%20Unknown' because the scheme does not have a registered handler. When I comment the line that calls the function, I have no error.
I've been struggling with this for many days, wasted time, several solutions, shit from M$, some ideas ?, I've seen permissions, do I need to register an object?
some ideas on what the problem might be, please remember, I have limited control on the Win Server. Thank you all
João