OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

MailMerge Statement Parameter

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
seballa
General User
General User


Joined: 15 Jun 2005
Posts: 22

PostPosted: Thu Jun 16, 2005 5:05 am    Post subject: MailMerge Statement Parameter Reply with quote

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
View user's profile Send private message
Danad
OOo Advocate
OOo Advocate


Joined: 22 Feb 2004
Posts: 293
Location: Brasil

PostPosted: Thu Jun 16, 2005 8:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group