George Bowyer
Registered User.
- Local time
- Today, 17:52
- Joined
- May 17, 2004
- Messages
- 50
Hello,
I use the following code to open a mailmerge from Access to word:
CreateMergeLetter "C:\Documents and Settings\Compaq_Owner\Application Data\Microsoft\Templates\MarkMerge.dot"
This is the CreateMergeLetter Routine:
Public Sub CreateMergeLetter(strTemplate As String)
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim frm As Form
' return reference to form
Set frm = Forms!frmUpdateNotes
' if Word open return reference to it
' else establish reference to it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = CreateObject("Word.Application")
End If
AppActivate "Microsoft Word"
On Error GoTo Err_Handler
' open Word document in maximised window
objWord.Visible = True
Set objDoc = objWord.Documents.Add(strTemplate)
objWord.WindowState = wdWindowStateMaximize
' insert text at bookmarks
InsertAtBookmarks objWord, objDoc, "BMDate", Format(VBA.Date, "d mmmm yyyy")
'Move Word cursor to starting point
objDoc.Bookmarks("BMStart").Select
Set objDoc = Nothing
Set objWord = Nothing
Exit_Here:
On Error GoTo 0
Exit Sub
Err_Handler:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume Exit_Here
End Sub
This always used to work fine, but recently for some reason it now opens the correct template, but the record source is blank and I have to open it manually.
I have tried resaving the template with the record source opened correctly, but next time I open it, the record source has gone again.
Can anyone help, please?
Thanks
George Bowyer
I use the following code to open a mailmerge from Access to word:
CreateMergeLetter "C:\Documents and Settings\Compaq_Owner\Application Data\Microsoft\Templates\MarkMerge.dot"
This is the CreateMergeLetter Routine:
Public Sub CreateMergeLetter(strTemplate As String)
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim frm As Form
' return reference to form
Set frm = Forms!frmUpdateNotes
' if Word open return reference to it
' else establish reference to it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = CreateObject("Word.Application")
End If
AppActivate "Microsoft Word"
On Error GoTo Err_Handler
' open Word document in maximised window
objWord.Visible = True
Set objDoc = objWord.Documents.Add(strTemplate)
objWord.WindowState = wdWindowStateMaximize
' insert text at bookmarks
InsertAtBookmarks objWord, objDoc, "BMDate", Format(VBA.Date, "d mmmm yyyy")
'Move Word cursor to starting point
objDoc.Bookmarks("BMStart").Select
Set objDoc = Nothing
Set objWord = Nothing
Exit_Here:
On Error GoTo 0
Exit Sub
Err_Handler:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume Exit_Here
End Sub
This always used to work fine, but recently for some reason it now opens the correct template, but the record source is blank and I have to open it manually.
I have tried resaving the template with the record source opened correctly, but next time I open it, the record source has gone again.
Can anyone help, please?
Thanks
George Bowyer