|
-
Mar 16th, 2010, 03:15 PM
#1
Thread Starter
New Member
[RESOLVED] Mail merge problem looping through records set
I need to create individual merge documents from Access and then attach each document to an email sent from Access. All works fine providing I do them one at a time. However, when I loop through a record set to send each one seperately, the first record goes through fine but then I get an error message "The remote server machine does not exist or is unavailable".
This is what I have so far
For Each varItem In ctlList.ItemsSelected
intMemberID = ListMFD.Column(1, varItem)
strEmailAddress = ListMFD.Column(6, varItem)
strContactName = ListMFD.Column(2, varItem)
strFee = "£" & ListMFD.Column(5, varItem) & ".00"
strMemNo = ListMFD.Column(3, varItem)
DteDue = ListMFD.Column(4, varItem)
'create mail merge reminder docs
Set objDoc = objWord.Documents.Open(strTemplatePath & "\RenewalMailMerge.doc")
objDoc.MailMerge.OpenDataSource Name:="", _
Connection:="DSN=MMSSQL;DATABASE=MMSSQL;uid=SWCAAMMS;pwd=swcaamms;", _
SQLStatement:="SELECT ShortName, MembershipNo, FeeNextDue " & _
"FROM VW_MembersFeeRemindersDueMM WHERE MembershipNo = '" & strMemNo & "'", _
LinkToSource:=True, AddToRecentFiles:=False
objDoc.MailMerge.Destination = wdSendToNewDocument
objDoc.MailMerge.Execute
objDoc.Close
objWord.Documents(1).SaveAs (strSavedDocsPath & "\" & strMemNo & "_" & Format(Now(), "yyyy") & "_Renewal.doc")
objWord.Documents.Close
objWord.Quit (Word.wdSaveChanges = False)
Next varitem
Can anyone help please.
-
Mar 16th, 2010, 03:56 PM
#2
Re: Mail merge problem looping through records set
objWord.Quit (Word.wdSaveChanges = False)
as you close word here it is no longer available to open the next document, only do this after finishing all documents
also you are closing the document, before the saveAs, which as you want to use it again, seems to be incorrect (inefficient), you only want to close the new document
Last edited by westconn1; Mar 16th, 2010 at 04:00 PM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 17th, 2010, 04:03 AM
#3
Thread Starter
New Member
Re: Mail merge problem looping through records set
Thanks Pete. Your a star. Any ideas on how you turn off outlook warnings when sending email as part of the same process. I am attaching each document to an email and sending them from the app but get the message "Aprogram is trying to send email on your behalf etc"?
-
Mar 17th, 2010, 04:19 AM
#4
Re: Mail merge problem looping through records set
robdog has posted some code to close outlook security warnings, but you would need to search for it, it may be in the faq thread at top of this forum
otherwise use findwindow and sendmessage APIs
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 17th, 2010, 04:53 AM
#5
Thread Starter
New Member
Re: Mail merge problem looping through records set
Thanks Pete, have searched everywhere but can't find it. Can you point me in the right direction to robdog's post please
-
Mar 17th, 2010, 06:04 AM
#6
Re: Mail merge problem looping through records set
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 17th, 2010, 06:29 AM
#7
Thread Starter
New Member
Re: Mail merge problem looping through records set
Thanks Pete, that will do the job nicely.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|