Hi All
I have a script that I use to run a mail merge from Access to Word.
This is executed from a form with a persons name.
this is the code i use:
I want to set the default save as path for the word doc this is created
The code to get the file path I want to use for the save as path is:
I dont know how to stitch this all together with a bit of code to set the SaveAs file path as word opens.
Can anyone help me please!!!
Thanks
Kev
I have a script that I use to run a mail merge from Access to Word.
This is executed from a form with a persons name.
this is the code i use:
Code:
Private Sub Command41_Click()
On Error GoTo ErrorHandling
DoCmd.SetWarnings False
DoCmd.Close acForm, "frmWriteToClient", acSaveYes
Dim mypath As String
Dim mypath3 As String
Dim Wordpath As String
Dim sDBPath As String
Dim oApp As Word.Application
Dim ThisDB As String
Dim oWord As Word.Document
Dim oMainDoc As Word.Document
Exit Sub
If (Me.LeadAuthority = "A") Then
Wordpath = Environ("office") & "\winword.exe"
mypath = Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
mypath3 = mypath & "LetterTemplates\ClientLetterADC.docx"
ThisDB = CurrentDb.Name
Set oApp = CreateObject("Word.Application")
Set oWord = oApp.Documents.Open(FileName:=mypath3)
oApp.Visible = True
With oWord.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = ThisDB
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [tblWriteToClient]"
End With
DoEvents
With oWord
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1
oWord.Close savechanges:=False
DoCmd.SetWarnings True
DoCmd.Close acForm, "frmWriteToClientCheck", acSaveNo
Else
Wordpath = Environ("office") & "\winword.exe"
mypath = Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
mypath3 = mypath & "LetterTemplates\ClientLetterWBC.docx"
ThisDB = CurrentDb.Name
Set oApp = CreateObject("Word.Application")
Set oWord = oApp.Documents.Open(FileName:=mypath3)
oApp.Visible = True
With oWord.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = ThisDB
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [tblWriteToClient]"
End With
With oWord
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1
oWord.Close savechanges:=False
DoCmd.SetWarnings True
DoCmd.Close acForm, "frmWriteToClientCheck", acSaveNo
End If
Exit Sub
ErrorHandling:
If Err.Number = 4198 Then
DoEvents
Resume
Else
MsgBox (Err.Number)
End If
I want to set the default save as path for the word doc this is created
The code to get the file path I want to use for the save as path is:
Code:
Dim FirstLetter As String
Dim Surname As String
Dim FolderPath As String
Dim WholePath As String
Surname = DLookup("Surname", "tblPerson", "ID =" & Me![SearchResults])
FirstLetter = Left(Surname, 1)
FolderPath = "N:\CASEWORK"
WholePath = FolderPath & "\" & FirstLetter & ""
I dont know how to stitch this all together with a bit of code to set the SaveAs file path as word opens.
Can anyone help me please!!!
Thanks
Kev