I’m using the below code to populate a word document. My users have requested that whenever a new city is encountered, to insert a page break. There is bascially 3 contacts per page, but they want it so if here is only 1 or 2 contacts, for the third cell to be skipped and to immediatly goto the next page for the following city. Is this possible?
Dim doc As New Document("d:\hart11\templates\canvassing.doc")
Dim adapterTemplate1 As New SQLDataAdapter("SELECT ‘’ AS SalesAmount, CompanyTxt AS Company, ‘’ AS EmploymentThisSite, FaxDirectTxt AS Fax, ‘’ AS Ownership, PhoneDirectTxt AS Phone, ‘’ AS [Plant/FacilitySize], PhoneGeneralTxt AS Phone2, WebURL AS WebAddress, ‘’ AS YearEstablished, ‘’ AS OwnsRents, Address1Txt AS Address1, Address2Txt AS Address2, CityTxt As City, StateCode AS State, PostalCodeTxt As Zip, ShippingAddress1Txt AS AltAddress, ShippingCityTxt As AltCity, ShippingStateCode AS AltState, ShippingPostalCodeTxt AS AltZip, CountyTxt AS County, ContactSIC1Code AS SIC1, ‘’ AS SIC1Description, ContactSIC2Code AS SIC2, ‘’ AS Sic2Description, ContactSIC3Code AS SIC3, ‘’ AS Sic3Description, ContactParentCompanyTxt AS Parent, PrefixTxt AS Prefix, FirstTxt AS First, LastTxt As Last, SuffixTxt AS Suffix, TitleTxt AS Title, DivisionTxt AS Division, ExportNameTxt AS Canvassed, ExportPreparedFor AS Salesperson FROM ViewContact INNER JOIN ExportDetail ON ExportDetail.ExportPrimaryRecordID = ViewContact.ContactID INNER JOIN ExportMaster ON ExportMaster.ExportID = ExportDetail.ExportID WHERE ExportDetail.ExportID=’" & Request.QueryString("ID") & "’ UNION SELECT [Sales Amount] AS SalesAmount, Company, EmploymentThisSite, REPLACE(Fax, ‘-’, ‘’) AS Fax, Ownership, REPLACE(Phone,’-’,’’) AS Phone, [Plant/FacilitySize], TollFree AS Phone2, WebAddress, YearEstablished, OwnsRents, MailAddress AS Address1, ‘’ AS Address2, MailCity AS City, MailState AS State, MailZipPlusExtension AS Zip, StreetAddress AS AltAddress, StreetCity AS AltCity, StreetState AS AltState, StreetZip AS AltZip, StreetCounty AS County, PrimarySic AS SIC1, PrimarySicDescription AS SIC1Description, Sic2 AS SIC2, Sic2Description, Sic3 AS SIC3, Sic3Description, ParentName AS Parent, RankedExecutive1Prefix AS Prefix, RankedExecutive1FirstName AS First, RankedExecutive1LastName AS Last, RankedExecutive1Suffix AS Suffix, RankedExecutive1TitleDescription AS Title, ‘’ AS Division, ExportNameTxt AS Canvassed, ExportPreparedFor AS Salesperson FROM ContactHarris INNER JOIN ExportMaster ON ExportMaster.ExportID = ContactHarris.ExportID WHERE ContactHarris.ExportID=’" & Request.QueryString("ID") & "’", myConnection)
Dim dtTemplate1 As New DataTable()
adapterTemplate1.Fill(dtTemplate1)
doc.MailMerge.Execute(dtTemplate1)
doc.MailMerge.DeleteFields()
doc.Save(SavePath)