View Single Post
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Rowena Rowena is offline
external usenet poster
 
Posts: 5
Default Mail merge only displaying some fields but not others

Hi,

I am automating a mail merge from VS2008 using an exising MS Word 2008
document. The merge seems to work. The query returns the correct number of
records and some of the fields are populated but not others. For the life of
me I can't figure out why some fields aren't populated. The dates and numeric
values work, but none of the text fields are populated.

Thanks!

Dim strSQL1, strSQL2 As String
strSQL1 = ""
strSQL2 = ""
strSQL1 = "SELECT [Permit], [PermitDate], DateAdd(yyyy, 2,
[PermitDate]) AS [ExpiryDate], [ExtDate], [Description], [Lot],
[DistrictLot], [Plan], [Address], [Inspector], '250-492-0237' AS
[InspectorPhoneNumber], "
strSQL2 = "[Name], [Maddress], [MCity], [Mpostal], [Earea], [Folio],
GetDate() AS [TodaysDate] FROM [permits] WHERE [Permit]0 AND [Active]=1 AND
[FarmStatus]='N' AND [PermitDate]GetDate()-670 AND
[PermitDate]GetDate()-730"

' Create an instance of Word and make it visible.
Dim wrdApp As New Word.Application
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True

' Open document.
Dim wrdDoc As Word.Document
wrdDoc = wrdApp.Documents.Open("warning.docx")
wrdDoc.MailMerge.OpenDataSource(Name:="",
Connection:="DSN=Permits;DATABASE=Permits;uid=uid; pwd=pwd;",
SQLStatement:=strSQL1, SQLStatement1:=strSQL2)
wrdDoc.MailMerge.Execute()

' Release References.
wrdDoc = Nothing
wrdApp = Nothing