>Hi:
>
>I am working in a project where I have to use a Mailmerge service based in SQL Server from VFP. I use the following connection but it doesn't work.
>
>owordcontract.ActiveDocument.MailMerge.OpenDataSource(,,,.T.,,,,,,,,"DRIVER={SQL SERVER};DATABASE=MBC;SERVER=MBCDEVTEST;UID=;PWD=","EXECUTE MBC_SP_LEGAL CT,'ALL','6'","")
>
>As you can see I am using a store Procedures instead a single query. I know the connection is good because I receive just the error message "Command Failed!" (That happen after connection)
>
>Can anyone see what is wrong with this picture?
>
>Thanks
>
>Efrain
Efrain,
Seemingly nothing wrong and I don't know why word fails on it. I can suggest a workaround though. Create an MSQuery in word and save it as a .dqy file. You might later check and edit that file manually or even create on the fly seeing the syntax. Then change your merge code to something like :
lcQueryFile = 'c:\myPath\My Query from SQLServer.dqy'
oWordDocument=Createobject("word.application")
oWordDocument.visible = .t.
With oWordDocument
.Documents.Add
.ActiveDocument.MailMerge.OpenDataSource(lcQueryFile)
PS: In MSQuery select no table or temporarily select anyone then delete, view the SQL and write "EXECUTE MBC_SP_LEGAL CT,'ALL','6'" there. Once you get the syntax in .dqy you might create new .dqy on the fly with your new parameters.
Cetin