Link to home
Start Free TrialLog in
Avatar of ChadB234
ChadB234

asked on

Mail Merge in VB6 directly to multi-page pdf

I need some expert advice on the best way to merge data from an MS SQL db directly to a multi-page pdf file. This has to be done with almost no user intervention at all, I want them to select some basic critera on the form and click "Merge" button and voila, the pdf opens with all the merged data in the document. This is used to create reminder letters for bill collection. The source document will be in a MS Word document, formatted for a #10 window envelope. Mail merge in Word is way too complicated for the users I'm dealing with. This merge will be handling as many as 10k letters per batch, so overhead is a concern.
I've been looking for a good pdf library to use, but haven't had much luck. Any recommendations on that?
Also, Acrobat Professional or any of those products will not be on the end user's machine-I'm looking for a solution with a stand-alone library.

Private Sub Merge_Click()
    	Dim cn As ADODB.Connection
    	Set cn = New ADODB.Connection
    
    	cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=" & DB & ";Data Source=" & SERVER
    
    	cn.Open cn, sqlUserName, sqlPassWord
    
    	Dim rs As ADODB.Recordset
    	Set rs = New ADODB.Recordset
    
    	rs.ActiveConnection = cn
    
    	rs.CursorLocation = adUseClient
    	rs.CursorType = adOpenStatic
    	rs.LockType = adLockBatchOptimistic
    
    	rs.Source = "select * from table where criteria= 'something'"
    
    	rs.Open
    
	"Open original source document from known location to read message body--document in .doc or .rtf"
	--code needed here    
    	"close the source document"

	"Create new instance of .pdf document to merge fields and source data into"

Do While Not rs.EOF

	"insert message body from source document"
	"replace or append data in orig document with data from db-Recipient Name"
	"replace or append data in orig document with data from db-C/O Information"
	"replace or append data in orig document with data from db-Address"
	"replace or append data in orig document with data from db-City, State Zip"
	
	"Insert Page Break"    

    	rs.MoveNext

Loop

	"Close the Output file"

	"Open Output file in default pdf viewer"

rs.close
cn.close

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SUDEEP G
SUDEEP G

Hi,

Download "Advanced Document Generator  from https://mailmergepdf.blogspot.in
You can generate PDF files from mail merge.
You can do lots of things using this software.