Hi Alex,
 
> I think you would probably need to establish a connection to the 
> database source and a db context first, and you would probably have to 
> "execute" the SQL rather than just use "command".

I found a solution[1] :

Sub TestMailMerge

  Dim myMailMerge As Object

  'Service myMailMerge
  myMailMerge = CreateUnoService("com.sun.star.text.MailMerge")

  'DataSourceName
  myMailMerge.DataSourceName = "Bibliography"

  'Source
  myMailMerge.DocumentURL = convertToURL(thisComponent.URL)

  'Mailmerge options
  'OK
  myMailMerge.CommandType = com.sun.star.sdb.CommandType.TABLE
  myMailMerge.Command = "biblio"

 '****************************************************************
   ' SQL query
   Dim oRowSet As Variant
   Dim cmdSQL As String
   oRowSet = createUnoService("com.sun.star.sdb.RowSet")
   oRowSet.setPropertyValue("DataSourceName", "Bibliography") 
   oRowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND
   cmdSQL = "SELECT * FROM ""biblio"" WHERE ""Year"" <> '2004'"
   oRowSet.setPropertyValue("Command", cmdSQL)
   oRowSet.execute() 

   'LinkResultset & Mailmerge
   myMailMerge.ResultSet = oRowSet 

   '********************************************************************
  
  'Save as single file
  myMailMerge.SaveAsSingleFile = True

  'By file
  myMailMerge.OutputType = com.sun.star.text.MailMergeType.FILE

  'PDF output
  myMailMerge.SaveFilter = "writer_pdf_export"

  'ODT output
  'myMailMerge.SaveFilter = "writer8"

  'output path
  myMailMerge.OutputUrl = ConvertToURL(PathMailMerge)

  'Execute mailmerge
  monPublipostage.execute(Array())
  monPublipostage.dispose() 

  MsgBox "Result is in " + PathMailMerge
End Sub


[1] http://www.oooforum.org/forum/viewtopic.phtml?t=34416




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to