| View previous topic :: View next topic |
| Author |
Message |
seballa General User

Joined: 15 Jun 2005 Posts: 22
|
Posted: Thu Jun 16, 2005 5:05 am Post subject: MailMerge Statement Parameter |
|
|
I managed to do a mailmerge by macro but I am having a problem again:
This is my code
| Code: | Sub Main
Parameter = InputBox( "Parameter?" )
oPathSettings = CreateUnoService( "com.sun.star.util.PathSettings" )
oMerge = createunoservice("com.sun.star.text.MailMerge")
oMerge.DocumentURL = ConvertToUrl("C:\dat.odt")
oMerge.DataSourceName = "MyDatabase"
oMerge.CommandType = 1
oMerge.Command = "myQuery"
oMerge.OutputType = 2
oMerge.OutputUrl = ConvertToUrl("C:\")
oMerge.FileNameFromColumn = False
Dim oProps as Object
oMerge.execute(oProps())
End Sub
|
It is working fine so far the problem starts when i want to call a query which needs a parameter input. Then I get an erorr message.
How can I set the statement parameterfor the query ?
Thanks for your help |
|
| Back to top |
|
 |
Danad OOo Advocate

Joined: 22 Feb 2004 Posts: 293 Location: Brasil
|
Posted: Thu Jun 16, 2005 8:34 pm Post subject: |
|
|
It seems that MailMerge doesn't works when a query needs a parameter, it calls the input parameter dialog but doesn't make a proper replacement.
You can create a command for your query and then exchange it by code (OOo 1.1.x):
| Code: |
Sub change_QueryCommand
'
' Based on code from "Introdução ao OpenOffice.org Basic - Versão 2"
' by Noelson Alves Duarte
'
oDbCont = createUnoService( "com.sun.star.sdb.DatabaseContext")
oDbFonte = oDbCont.getByName("Bibliography")
oDbCon = oDbFonte.getConnection("","")
oDefCons = oDbCon.getQueries()
oConsulta = oDefCons.getByName("qry1")
msgBox oConsulta.Command
sParam = InputBox("Identifier:")
cmdSQL = "SELECT " & """" & "Identifier" & """" & ", " & """" & "Author" & """" &_
" FROM " & """" & "biblio" & """" & " " & """" & "biblio" & """" &_
" WHERE ((" & """" & "Identifier" & """" & " = " & "'" & sParam & "'))"
oConsulta.Command = cmdSQL
oDefCons.flush()
msgBox oConsulta.Command
'
End Sub
|
Sintax of query commands depends on what DB you are using.
HTH |
|
| Back to top |
|
 |
|