I am using the MailMerge AOO Basic Macro support to create formatted statements of account. As an intrinsic part of the system they should work in TEST as well as in LIVE. But they don't. I am at a loss as to what might be the cause. Any clues will be welcome.
They run from a dos batch file which accepts one of three values for a single parameter and calls the macro passing that value.
The relevant portion of the batch job (omitting only a heap of if (not) exist, copy, and move statements) is as follows
Code: Select all
if "%1" NEQ "LIVE" (
if "%1" NEQ "TEST" (
if "%1" NEQ "UPGRADES" (
echo Value Inadmissible
exit /b 99
)
)
)
set _subdir=%1
Code: Select all
"c:\Program Files (x86)\OpenOffice 4\program\soffice.exe" -headless -n "macro:///accountingReports.bankStatements.Main(%_subdir%)"
The macro itself contains the following code
Code: Select all
REM ***** BASIC *****
Sub Main(systemInstance as string)
Dim args(0) As New com.sun.star.beans.PropertyValue
Dim sURL As String
sURL = "file:///C:/Users/Accounts/Bookkeeping/CODE/MASTERS/bankStatements.odt"
args(0).Name = "MacroExecutionMode"
args(0).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE_NO_WARN
StarDesktop.LoadComponentFromUrl(sURL, "_default", 0, args())
udp = ThisComponent.DocumentProperties.getUserDefinedProperties()
mm = createUnoService("com.sun.star.text.MailMerge")
with mm
.DataSourceName = systemInstance ' udp.MRG_DataSource
print .DataSourceName
.CommandType = 0 ' udp.MRG_SourceType
.Command = "PUBLIC.PUBLIC.View STATEMENTS" ' udp.MRG_Source
.EscapeProcessing = true ' not udp.MRG_DirectSQL
.DocumentURL = ThisComponent.getURL()
print .DocumentURL
.OutputType = com.sun.star.text.MailMergeType.FILE
.SaveAsSingleFile = True
.OutputURL = "file:///C:/Users/Public/Accounts/reports/temp/" ' udp.MRG_OutputPath
.FileNamePrefix = "Bank Statement " ' udp.MRG_FileNamePrefix
.execute(Array())
end with
Dim oDoc
oDoc = ThisComponent
If HasUnoInterfaces(oDoc, "com.sun.star.util.XCloseable") Then
oDoc.close(true)
Else
oDoc.dispose()
End If
End Sub
When I run the batch job with LIVE the formatted and populated statements appear correctly.
When I run it with TEST only the prefilled text appears.
Baffled!
However I note one further thing.
Looking at the mailmerge source document, hovering the mouse over any field label shows the prefix LIVE. to the datasource and field name. So I guess this is a hard coded feature and accordingly I would need a copy of the mailmerge source corresponding to each system instance in which I want to run it.
Is this correct?
Is there any way of deferring evaluation of the datasource name to run time? Well, the macro thinks so, otherwise .DataSourceName would not be a variable. It would seem that the "template" field definitions override this and prevent assigning .DataSourceName at execution time.
The community's observations will be very welcome.
Thanks in advance
David
Edit: I have just had a look at the .odt file, unzipped, and content.xml contains lines such as the following
Code: Select all
So that confirms the above. My next question is: how can I substitute this at run time? I can see DatabaseLocation, ConnectionResource, and ActiveConnection in service DataAccessDescriptor. Are these useful to explore? Or: maybe I need to learn how to create the .odt "raw" with the text fields and their masters etc. Where can I find this? Too many questions... |