Automating Mail Merge with VB.Net and Office XP and Office 2000 produces mixed results 
Author Message
 Automating Mail Merge with VB.Net and Office XP and Office 2000 produces mixed results

I perform merges automatically from my SQL databases in VB.Net by creating a
text (delimited) file then opening the datasource through code.  In VB6
(which I translated the code from) this process works fine on either word
2000 or Word 2002... From VB.Net, the process works on Word XP, but will not
open the datasource file when using Word 2000.  I have made sure to use the
lowest common denomenator features to ensure compatibility.

Here is the code that is crashing

Select Case myValue3

Case 0

myValue3 = CInt(Int((14923 * Rnd()) + 1))

FileOpen(1, Application.StartupPath & "\merging\" & CStr(myValue3) & ".txt",
OpenMode.Output)

adoMain.Open("Select * from WordMerge1 where contactid = 0", adoConnection)

For gencount = 1 To adoMain.Fields.Count - 1

Write(1, adoMain.Fields(gencount).Name)

Next

adoMain.Close()

WriteLine(1)

For Each lstRecipient In ListView1.Items

Select Case lstRecipient.SubItems(2).Text

Case Is > 0

adoMerge.Open("Select * from wordmerge2 where contactID = " &
lstRecipient.Tag & " and mrgprojectid = " & lstRecipient.SubItems(2).Text,
adoConnection)

Case Else

adoMerge.Open("Select * from wordmerge1 where contactID = " &
lstRecipient.Tag, adoConnection)

End Select

For gencount = 1 To adoMerge.Fields.Count - 1

Select Case IsDBNull(adoMerge(gencount).Value)

Case False

Write(1, adoMerge(gencount).Value)

Case True

Write(1, "")

End Select

Next

adoMerge.Close()

WriteLine(1)

Next

FileClose(1)

Case Else

myValue4 = myValue3 + 1

FileCopy(Application.StartupPath & "\merging\" & CStr(myValue3) & ".txt",
Application.StartupPath & "\merging\" & CStr(myValue4) & ".txt")

myValue3 = myValue3 + 1

End Select

With objWord.Selection

If objWord.ActiveDocument.MailMerge.State = 2 Then

objWord.ActiveDocument.MailMerge.MainDocumentType = -1

End If

objWord.ActiveDocument.MailMerge.MainDocumentType = 0

Select Case myValue4

Case Is > 0

objWord.ActiveDocument.MailMerge.OpenDataSource(Name:=Application.StartupPat
h & "\merging\" & CStr(myValue4) & ".txt", ConfirmConversions:=False)

Case Else

objWord.ActiveDocument.MailMerge.OpenDataSource(Name:=Application.StartupPat
h & "\merging\" & CStr(myValue3) & ".txt", ConfirmConversions:=False)

End Select

objWord.ActiveDocument.MailMerge.EditMainDocument()

Help

Philip Carter



Sat, 18 Jun 2005 14:55:06 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Office 2000 and Office XP question

2. Office XP Run Time Error after upgrade from Office 2000

3. Behavior under Office 2000 vs. Office XP

4. Automating Mail Merge from a non office program(Java)

5. Mail Merge in Office XP

6. Getting Error Code:5922 when running word mail merge on Office XP

7. Office XP Mail Merge issue Insertdatabase issue and problems with copying a macro

8. Bug in MSCAL.OCX 10.0.0.2601 Win 2000 Office XP VB

9. VB.Net and Office (97, 2000, 2002)

10. Office 97 Vs. Office 2000

11. Office 2000 & Office 97 Automation Error

12. Office 2000 vs office 97

 

 
Powered by phpBB® Forum Software