Hi All
I realise there are a lot of threads about this, but i cant find my solution anywhere.
I have a split db. I would like to automate standard letters from the data in the db. I have a button which runs the code below.
Basically it creates a table called tblCurrentClientForLetterTemplate, this contains only the customer that is currently being looked at. (this works)
The code then opens a word template. (this works)
It is then meant to set up the datasource in word and create the letter - but it doesn't
the code is:
It works up to the oApp.Visible = True point.
I have selected the word11 reference library.
Please can anyone point me in the right direction?
edit - I meant to say, some of the code may seem a bit unneccesarily lenghty, but the database needs to work on different platforms (from network, desktop, within citrix etc) so I have had to set up ways of obtaining current file paths for the db, word doc and exe files.
Kind Regards
Kev
I realise there are a lot of threads about this, but i cant find my solution anywhere.
I have a split db. I would like to automate standard letters from the data in the db. I have a button which runs the code below.
Basically it creates a table called tblCurrentClientForLetterTemplate, this contains only the customer that is currently being looked at. (this works)
The code then opens a word template. (this works)
It is then meant to set up the datasource in word and create the letter - but it doesn't
the code is:
Code:
DoCmd.SetWarnings False
Dim mypath As String
Dim mypath2 As String
Dim Wordpath As String
Dim folder As String
Dim sDBPath As String
Wordpath = Environ("office") & "\winword.exe"
mypath = Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
mypath2 = ("" & Wordpath & " """ & mypath & "merge test.doc""")
DoCmd.RepaintObject , ""
DoCmd.OpenQuery "qryForLetterTemplate2", acViewNormal, acEdit
folder = CurrentProject.Path
Call Shell(mypath2)
oApp.Visible = True
With oMainDoc.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = folder & "new housing database v6 FE.mdb"
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [tblCurrentClientForLetterTemplate]"
End With
With oMainDoc
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1
DoCmd.SetWarnings True
It works up to the oApp.Visible = True point.
I have selected the word11 reference library.
Please can anyone point me in the right direction?
edit - I meant to say, some of the code may seem a bit unneccesarily lenghty, but the database needs to work on different platforms (from network, desktop, within citrix etc) so I have had to set up ways of obtaining current file paths for the db, word doc and exe files.
Kind Regards
Kev