Hi all
Sorry to keep returning, but my DB is starting to be really functional with all your help!
I am using this code to run a mail merge:
This results in a word file open called Letters1 (i think, at least thats what the title bar has in it)
I want to go one step further though...
I have a filing system whereby there is a folder for each letter of the alphabet. I have other code that use use to open the correct folder:
I would like the mail merge code to do something simiar to the open folder code, in that, after the code runs I want a word Save As dialogue box to open which is already pointing to the correct folder.
The only ideas I have so far is that I could use something like this:
except it seems to break on the last line and i'm not sure what it should be.
Sorry for the long post, hope i've explained what id like to do well enough.
Kev
Sorry to keep returning, but my DB is starting to be really functional with all your help!
I am using this code to run a mail merge:
Code:
DoCmd.SetWarnings False
Dim mypath As String
Dim mypath3 As String
Dim Wordpath As String
Dim folder 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
Wordpath = Environ("office") & "\winword.exe"
mypath = Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
mypath3 = ("" & mypath & "merge test.doc""")
ThisDB = CurrentDb.Name
DoCmd.RepaintObject , ""
DoCmd.OpenQuery "qryForLetterTemplate2", acViewNormal, acEdit
folder = CurrentProject.Path & "\"
Set oApp = CreateObject("Word.Application")
Set oWord = oApp.Documents.Open(FileName:=mypath3)
oApp.Visible = True
With oWord.MailMerge
.MainDocumentType = wdFormLetters
' sDBPath = folder & "new housing database v7 FE.mdb"
sDBPath = ThisDB
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [tblCurrentClientForLetterTemplate]"
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
This results in a word file open called Letters1 (i think, at least thats what the title bar has in it)
I want to go one step further though...
I have a filing system whereby there is a folder for each letter of the alphabet. I have other code that use use to open the correct folder:
Code:
Dim FirstLetter As String
FirstLetter = Left(Me!Surname, 1)
Dim FolderPath As String
FolderPath = "N:\CASEWORK"
Shell "C:\WINDOWS\explorer.exe """ & FolderPath & "\" & FirstLetter & "", vbNormalFocus
I would like the mail merge code to do something simiar to the open folder code, in that, after the code runs I want a word Save As dialogue box to open which is already pointing to the correct folder.
The only ideas I have so far is that I could use something like this:
Code:
Dim FirstLetter As String
FirstLetter = Left(Me!Surname, 1)
Dim FolderPath As String
FolderPath = "N:\CASEWORK"
oApp.SaveAs Filename:=FolderPath & "\" & FirstLetter & ".doc"
except it seems to break on the last line and i'm not sure what it should be.
Sorry for the long post, hope i've explained what id like to do well enough.
Kev