Hi,
I even have a class for you:
------------------
require ''win32ole''
module Output
# Singleton class used in order to manipulate MS Access
class Access
private_class_method :new
@@access = nil
# Returns a valid Access class
def Access.open(database)
@database = File.expand_path(database)
self
end
# Destroys any remaining Access internal reference
def Access.close
@@access.quit
rescue
#puts "Could not close the MS Access OLE object."
end
# Creates a fresh MS Access OLE Automation server.
def Access.init
Access.close
@@access = WIN32OLE.new(''Access.Application'')
@@access.OpenCurrentDatabase(@database)
end
# Runs the command. The first parameter is the name of the function, and
# the other parameters are the parameters of the function
def Access.run_command(command, *param)
begin
@@access.run(command, *param)
rescue
#puts "MS Access call failed. It might have been closed meanwhile,
so we do a second attempt after initializing MS Access again."
Access.init
@@access.run(command, *param)
end
rescue
Access.close
raise _("Win32 OLE error: could not run the command.")
end
# Prints a MS Access report on the default printer
# without showing the print dialog.
def Access.print_report(report, where = "")
# We try closing the Access report.
begin
Access.close_report(report)
rescue
#puts "Closing MS Access call failed."
end
# We try printing the MS Access report.
begin
@@access.DoCmd.OpenReport(report, 0, "", where)
rescue
#puts "MS Access call failed. It might have been closed meanwhile,
so we do a second attempt after initializing MS Access again."
Access.init
@@access.DoCmd.OpenReport(report, 0, "", where)
end
rescue
Access.close
#raise _("Win32 OLE error: could not print the Access report.")
end
# Shows a MS Access report without printing it.
def Access.show_report(report, where = "")
# We try closing the Access report.
begin
Access.close_report(report)
rescue
#puts "Closing MS Access call failed."
end
# We try showing the MS Access report.
begin
@@access.DoCmd.OpenReport(report, 2, "", where)
@@access.visible = true
rescue
#puts "MS Access call failed. It might have been closed meanwhile,
so we do a second attempt after initializing MS Access again."
Access.init
@@access.DoCmd.OpenReport(report, 2, "", where)
@@access.visible = true
end
rescue
Access.close
#raise _("Win32 OLE error: could not show the Access report.")
$app.endWaitCursor()
FXMessageBox.error($wrk, MBOX_OK, _("Error"), "Le report
est vide, impossible de l''afficher.")
$app.beginWaitCursor()
end
# Closes a MS Access report.
def Access.close_report(report)
@@access.DoCmd.close(3, report)
end
end
end
------------------
You can use it that way:
db = Access.open("reporting.mdb")
db.run_command("get_document_bvr_store", @id.val)
db.show_report("document_bvr")
... where "get_document_bvr_store" is a function like:
------------------
Option Compare Database
Option Explicit
Const GUIL = """"
Const APOST = "''"
Public Sub get_document_bvr_store(document As String)
On Error GoTo get_document_bvr_storeError
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Dim query As String
setMouseWait
query = "get_document_bvr"
Set MyDatabase = CurrentDb()
If (QueryExists(query)) Then MyDatabase.QueryDefs.Delete query
Set MyQueryDef = MyDatabase.CreateQueryDef(query)
MyQueryDef.Connect = "ODBC;DSN=soagesmat;"
MyQueryDef.SQL = "SELECT * FROM public." &
"""" & query & """" &
"(" & document & ");"
MyQueryDef.ReturnsRecords = True
MyQueryDef.Close
Set MyQueryDef = Nothing
MyDatabase.Close
Set MyDatabase = Nothing
get_document_bvr_storeExit:
setMouseNormal
Exit Sub
get_document_bvr_storeError:
MsgBox "Error in get_document_bvr_store."
Resume get_document_bvr_storeExit
End Sub
---------------------
This function modifies a query at run-time. This query is used as a datasource
for the report you want to open.
Regards,
Philippe
________________________________
De : Stuart Clarke [mailto:stuart_clarke86 at yahoo.com]
Envoy? : lundi, 9. mars 2009 20:14
? : Philippe Lang
Objet : RE: [fxruby-users] Reporting with FX
Hi,
Thanks for the reply. Do you have any documentation on this? Sounds interesting.
Regards
Stuart
--- On Mon, 9/3/09, Philippe Lang <philippe.lang at attiksystem.ch> wrote:
From: Philippe Lang <philippe.lang at attiksystem.ch>
Subject: RE: [fxruby-users] Reporting with FX
To: stuart_clarke86 at yahoo.com, fxruby-users at rubyforge.org
Date: Monday, 9 March, 2009, 8:40 AM
Hi,
We are simply MS Access for reporting in our software. This is absolutely not
cross-platform, but it works, and works well. With a few COM calls, you can
integrate MS Access into your application. And thanks to the MS Access runtime,
you don''t need a licence of MS Access on each computer.
Philippe Lang
Attik System
http://www.attiksystem.ch/beerp/beerp-the-fxruby-erp/
<http://www.attiksystem.ch/beerp/beerp-the-fxruby-erp/>
________________________________
De : fxruby-users-bounces at rubyforge.org [mailto:fxruby-users-bounces at
rubyforge.org] De la part de Stuart Clarke
Envoy? : dimanche, 8. mars 2009 17:31
? : fxruby-users at rubyforge.org
Objet : [fxruby-users] Reporting with FX
Hi all,
What is the best way to create reports with FX? I am looking to create HTML or
PDF reports.
Any ideas?
Many thanks
Stuart