Good Afternoon All,
I think I have an easy quesiton but cannot seem to figure this one out.
I have a mailmerge set up that looks at a "pending" field in a temp table. if the pending field is = "test1" then it grabs a letter1 and saves it to the share drive. The problem is the code loops through and if the "pending" field is "test2" then it goes and grabs a different letter and saves it as the same file as the first loop did. What is happening is the letters are overwriting themselves. Is there a way to tell the code to "append" the letters as opposed to overwriting eachother everytime it loops?
The code below is the part of the function that merges and saves the letter.
There must be a way to tell the letter in the save process to allow future "inserts".
THank you in advance for any help you can provide..
Tallman
I think I have an easy quesiton but cannot seem to figure this one out.
I have a mailmerge set up that looks at a "pending" field in a temp table. if the pending field is = "test1" then it grabs a letter1 and saves it to the share drive. The problem is the code loops through and if the "pending" field is "test2" then it goes and grabs a different letter and saves it as the same file as the first loop did. What is happening is the letters are overwriting themselves. Is there a way to tell the code to "append" the letters as opposed to overwriting eachother everytime it loops?
The code below is the part of the function that merges and saves the letter.
PHP:
Private Function Merge(strDoc As String)
'Name of database that hold the records you want to merge
Dim stDatabase As String
stDatabase = "S:\test.mdb"
Dim docPath As String
Dim strDocName As String
Dim dte As String
dte = Replace(CStr(Date), "/", "-")
'Location where the document is stored
docPath = "S:\test\test1\"
'Full path name of the document
strDocName = docPath & strDoc
'Open Word application and non-template document
Set wdApp = GetObject("", "Word.Application")
wdApp.Visible = True 'Remove this line to make process run in the background
Set wdDoc = wdApp.Documents.Open(strDocName, , False)
'SQL Statement that determines which records to merge
Dim strSQL As String
strSQL = "SELECT * " & _
"FROM [test_TMP] "
' Set the mail merge data source as the database.
wdDoc.MailMerge.OpenDataSource _
Name:=stDatabase, _
LinkToSource:=True, _
Connection:="TABLE [test_TMP]", _
SQLStatement:=strSQL
wdDoc.MailMerge.Execute
'set document as non-merge
wdDoc.MailMerge.MainDocumentType = -1 'NotAMergeDocument
'Save merged document as new name
wdApp.ActiveDocument.SaveAs ("S:\tallman\60PendWklyClientltr " & dte & " ")
'Save and close the non-merge document
wdDoc.Save
wdDoc.Close 0
'Close the application
wdApp.Quit False
End Function
There must be a way to tell the letter in the save process to allow future "inserts".
THank you in advance for any help you can provide..
Tallman