Question : Mail Merge

Hi

I have this problem with mail merge. When I first open a document from access it works as required, but when I open the document again (each time I open the document it will contain different Patient information) I get a different result.

The first document opens, Text is added I select Save it saves the document and return to access.

every time after that the document opens I select save, the document saves ok but I am left with the Template still open and get asked if I want to save that also.

If I close Access then reopen, it works ok for the first time then as above

below is the code I am using

Dim objWord As Word.Document
Dim Tpath, Tremove, PathToSave
Dim strFullPathAndFilename As String
Dim Tpatnum
T_Letters = "\\Cassey-server\Data\TempPlates\"
Tdoc = Me!txtDoc
Tpath = T_Letters & Tdoc
Tpatnum = Me!txtPatientNumber & "-" & Format(Now(), "dd-mmm-yyyy-hhmmss") & ".doc\"
PathToSave = "\\Cassey-Server\Data\PSRMSsavedLetters\" & Tpatnum
Set objWord = GetObject(Tpath, "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.Execute
objWord.Application.ActiveDocument.SaveAs PathToSave
Selection.MoveDown wdLine, 16
objWord.Close
Set objWord = Nothing

The Selection.Movedown wdLine, 16 also works on the first document but not on any other instant of open a document unless I close Access and reopen


Could the problem be when I open the document Word opens access again so the first document operates as it should


I have been looking at an old Paradox dB using Word mail merge using Word basic it seems so much simpler and it works like a charm

Any help with this problem would be most appreciated. Due to the complexity of the question and a solution required if possible ASP. I will start with 250 points and Add points if  required

chestera

Answer : Mail Merge

Maybe wrapping it all up with a word.application object will help you tidy things up:

T_Letters = "\\Cassey-server\Data\TempPlates\"
Tdoc = Me!txtDoc
Tpath = T_Letters & Tdoc
Tpatnum = Me!txtPatientNumber & "-" & Format(Now(), "dd-mmm-yyyy-hhmmss") & ".doc\"
PathToSave = "\\Cassey-Server\Data\PSRMSsavedLetters\" & Tpatnum
Set objApp = New Word.Application
'Set objWord = GetObject(Tpath, "Word.Document")
Srt objWord = objApp.Documents.Open(Tpath)
objWord.Application.Visible = True
objWord.MailMerge.Execute
objWord.Application.ActiveDocument.SaveAs PathToSave
selection.MoveDown wdLine, 16
objWord.Close
Set objWord = Nothing
objApp.Quit False
Set objApp = nothing

Dave
Random Solutions  
 
programming4us programming4us