Link to home
Start Free TrialLog in
Avatar of imnotahomey
imnotahomey

asked on

Calling a Microsoft Access Report from Java

Anyone got any ideas or sites where I can try to find out how to call a Microsoft Access Report from a Java application?
Avatar of Mick Barry
Mick Barry
Flag of Australia image

think you're only option would be to start Access using Runtime.exec()
Avatar of imnotahomey
imnotahomey

ASKER

I need to pass parameters to the access report from my Java program. I would prefer not having to redo the entire report in another reporting tool.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hm...i suggest you to create dll in C++ or VB which is do everything you want with MS Access through COM model.
   Then use JNI mechanism to call dll functions from Java and pass parameters to it.

   Read JNI tutorial at java.sun.com to understand JNI
create a shortcut to the report from access (this creates a shortcut file with a .mar extension I belive.  Then use Runtime.exec() and open that shortcut.  Then you open your report directly :)
>>I need to pass parameters to the access report from my Java program.

I don't think you can pass info directly, but there is a way to do it.  Configure your report to pull whatever info you need from a table and use jdbc to pass info from your java app to your Access database.  Just use an Insert query.  If you need further explanation let me know.  I have been in this same predicament before.

After you have updated the table with the appropraite info, here is the command you can use to open the report (This worked for me with Access 2000 on a Windows XP machine)

Runtime load = Runtime.getRuntime();        
//open the file
load.exec("\"C:\\Program Files\\Microsoft Office\\Office\\MSACCESS.EXE\" /NOSTARTUP /SHELLSYSTEM [OpenReport \"C:\\Report.mar\",2]\"");

It looks confusing but basically this is the command your pc uses when you click on the report shortcut.
Thanks everyone for your help.
I found some answers in the Access topic thanks to objects
I will probably end up running the following command line that i got from Mr TextReport, which made me happy
------------------------
"C:\Program Files\Microsoft Office\Office\MSAccess.exe" "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb" /x MacroName /CMD "[MyField]=5"

Function PrintReport
     docmd.openreport "MyReport", , Command$
End Function

and the macro does a runcode PrintReport()
-------------------------
Boog.