MS Word Merge problems using VFP 9.0  
Author Message
JoeW





PostPosted: Wed Sep 28 10:50:59 CDT 2005 Top

Exchange Servers >> MS Word Merge problems using VFP 9.0

I am having a lot of problems getting a MS Word Merge to work from VFP 9.0.
I swear it used to work in 6.0. I am getting the error message "OLE
IDispatch exception code 0 from Microsoft Word: Word was unable to open the
data source..."

Below is a majority of the code. The last line is what generates to error.
TIA for taking a look.

Thisform.Wordmailmerge1.cSQL = ""
Thisform.Wordmailmerge1.cDataPath = SYS(5) + CURDIR()
Thisform.Wordmailmerge1.cDataSource = "OUTPUTER"
Thisform.Wordmailmerge1.cFormLetter = ALLTRIM(THISFORM.PrimaryDOC.VALUE)
Thisform.Wordmailmerge1.lSave = .T.
Thisform.Wordmailmerge1.cSaveAsFolder = FOLDERNAMEIS
Thisform.Wordmailmerge1.cSaveAsName = FILENAMEIS
Thisform.Wordmailmerge1.Merge



Local oWord, lcFileName, lcConnectionString, oFormLetter

If Empty(This.cSQL) Then
This.cSQL = "SELECT * FROM " + This.cDataSource
Endif

lcFilename = addbs(This.cDataPath) + This.cDataSource + ".DBF"

If !Directory(This.cDataPath) Then
Messagebox("Invalid Datapath specified : " + This.cDatapath, 0, "Error")
Return
Endif

If !File(Addbs(This.cDatapath) + This.cDataSource + ".DBF") Then
Messagebox("Datasource " + addbs(This.cDatapath) + This.cDataSource + ".DBF
does not exist", 0, "Error")
Return
Endif

If !File(This.cFormLetter) Then
Messagebox("Form Letter " + This.cFormLetter + " does not exist", 0,
"Error")
Return
Endif



lcConnectionString = "DSN=FoxPro Files - Word;UID=;PWD=;SourceDB=" +
This.cDataPath +
";SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=MACHINE;Null=Yes;D
eleted=Yes;"

On Error Do MSMergeError

oWord = GetObject(,"Word")

*ON ERROR DO errhandler WITH ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ),
LINENO( )

ON ERROR

If Type("oWord") != "O" Then
oWord = CreateObject("Word.Application")

If Type("oWord") !="O" Then
MessageBox("Unable to start MS Word", 0, "Error")
Return
Endif
Endif

With oWord
.visible=.t.
EndWith


lnSelectArea=select()

oWord.Documents.Open(This.cFormLetter, .F., .F., .F., "", "", .F., "", "",
0)
oFormLetter = oWord.ActiveDocument
oWord.ActiveDocument.MailMerge.OpenDataSource(lcFilename, 0, .F., .F., .T.,
.F., "", "", .F., "", "", lcConnectionString, This.cSQL, "")




BR

Exchange Server19  
 
 
Leemi





PostPosted: Wed Sep 28 10:50:59 CDT 2005 Top

Exchange Servers >> MS Word Merge problems using VFP 9.0 Hi Big Bubba:

I have seen a problem with mail merge when people upgrade they version of
Word and add SP3.

Look at this article:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;825765

I hope this helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Sincerely,
Microsoft FoxPro Technical Support
Lee Mitchell

*-- VFP9 HAS ARRIVED!! --*
Read about all the new features of VFP9 here:
http://msdn.microsoft.com/vfoxpro/

*--Purchase VFP 9.0 here:
http://www.microsoft.com/PRODUCTS/info/product.aspx?view=22&pcid=54787e64-52
69-4500-8bf2-3f06689f4ab3&type=ovr

Keep an eye on the product lifecycle for Visual FoxPro here:
http://support.microsoft.com/gp/lifeselectindex
- VFP5 Mainstream Support retired June 30th, 2003
- VFP6 Mainstream Support retired Sept. 30th, 2003

>I am having a lot of problems getting a MS Word Merge to work from VFP 9.0.
>I swear it used to work in 6.0. I am getting the error message "OLE
>IDispatch exception code 0 from Microsoft Word: Word was unable to open the
>data source..."

>Below is a majority of the code. The last line is what generates to error.
>TIA for taking a look.

>Thisform.Wordmailmerge1.cSQL = ""
>Thisform.Wordmailmerge1.cDataPath = SYS(5) + CURDIR()
>Thisform.Wordmailmerge1.cDataSource = "OUTPUTER"
>Thisform.Wordmailmerge1.cFormLetter = ALLTRIM(THISFORM.PrimaryDOC.VALUE)
>Thisform.Wordmailmerge1.lSave = .T.
>Thisform.Wordmailmerge1.cSaveAsFolder = FOLDERNAMEIS
>Thisform.Wordmailmerge1.cSaveAsName = FILENAMEIS
>Thisform.Wordmailmerge1.Merge



>Local oWord, lcFileName, lcConnectionString, oFormLetter

>If Empty(This.cSQL) Then
> This.cSQL = "SELECT * FROM " + This.cDataSource
>Endif

>lcFilename = addbs(This.cDataPath) + This.cDataSource + ".DBF"

>If !Directory(This.cDataPath) Then
> Messagebox("Invalid Datapath specified : " + This.cDatapath, 0, "Error")
> Return
>Endif

>If !File(Addbs(This.cDatapath) + This.cDataSource + ".DBF") Then
> Messagebox("Datasource " + addbs(This.cDatapath) + This.cDataSource +
".DBF
>does not exist", 0, "Error")
> Return
>Endif

>If !File(This.cFormLetter) Then
> Messagebox("Form Letter " + This.cFormLetter + " does not exist", 0,
>"Error")
> Return
>Endif



>lcConnectionString = "DSN=FoxPro Files - Word;UID=;PWD=;SourceDB=" +
>This.cDataPath +
>";SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=MACHINE;Null=Yes;
D
>eleted=Yes;"

>On Error Do MSMergeError

>oWord = GetObject(,"Word")

>*ON ERROR DO errhandler WITH ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ),
>LINENO( )

>ON ERROR

>If Type("oWord") != "O" Then
> oWord = CreateObject("Word.Application")

>If Type("oWord") !="O" Then
> MessageBox("Unable to start MS Word", 0, "Error")
> Return
>Endif
>Endif

>With oWord
>.visible=.t.
>EndWith


>lnSelectArea=select()

>oWord.Documents.Open(This.cFormLetter, .F., .F., .F., "", "", .F., "", "",
>0)
>oFormLetter = oWord.ActiveDocument
>oWord.ActiveDocument.MailMerge.OpenDataSource(lcFilename, 0, .F., .F., .T.,
>.F., "", "", .F., "", "", lcConnectionString, This.cSQL, "")

>BR