D
Doctorjones_md
I'm pretty sure this is possible, but I'm lost in trying to figure it out
....
I have (2) pieces of code which work individually -- I need to
modify/incorporate the two so that they print data into the same WORD
template
Here's my code:
================
(This sub prints the data on an ACCESS form)
Private Sub Command83_Click()
On Error GoTo Err_Command83_Click
Dim stDocName As String
Dim MyForm As Form
stDocName = "PrintDetails"
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
DoCmd.PrintOut (I need to be able to specify the document to print to --
at a bookmarked location)
DoCmd.SelectObject acForm, MyForm.Name, False
Exit_Command83_Click:
Exit Sub
Err_Command83_Click:
MsgBox Err.Description
Resume Exit_Command83_Click
End Sub
===========================================
(This piece of code inserts some data into bookmarks -- no problem with
this -- it effectively print into the WORD template)
Sub CreateLetter(strTemplate As String)
' Opens a document in Word and inserts values from
' current record at bookmarks in Word document.
' Accepts: path to Word template file - String
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim frm As Form
Dim strAddress As String
' return reference to form
Set frm = Forms!frmAddresses
' 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, getting values from form
InsertAtBookmarks objWord, objDoc, "FirstName", frm!FirstName
InsertAtBookmarks objWord, objDoc, "LastName", frm!LastName
strAddress = (frm!Address + vbNewLine) & (frm!Address2 + vbNewLine) & _
(frm!City.Column(1) + vbNewLine) & (frm!County + vbNewLine) &
frm!PostCode
InsertAtBookmarks objWord, objDoc, "Address", strAddress
InsertAtBookmarks objWord, objDoc, "CurrentDate", Format(VBA.Date(), "d
mmmm yyyy")
InsertAtBookmarks objWord, objDoc, "ToName", frm!FirstName
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
==========================================
What I need is to be able to change the "DoCmd.PrintOut" in the 1st piece of
code so that the data on the "Print Details" form will print at a Bookmarked
location in an EXISTING Word Template.
How would I go about doing this?
Thanks in advance ...
....
I have (2) pieces of code which work individually -- I need to
modify/incorporate the two so that they print data into the same WORD
template
Here's my code:
================
(This sub prints the data on an ACCESS form)
Private Sub Command83_Click()
On Error GoTo Err_Command83_Click
Dim stDocName As String
Dim MyForm As Form
stDocName = "PrintDetails"
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
DoCmd.PrintOut (I need to be able to specify the document to print to --
at a bookmarked location)
DoCmd.SelectObject acForm, MyForm.Name, False
Exit_Command83_Click:
Exit Sub
Err_Command83_Click:
MsgBox Err.Description
Resume Exit_Command83_Click
End Sub
===========================================
(This piece of code inserts some data into bookmarks -- no problem with
this -- it effectively print into the WORD template)
Sub CreateLetter(strTemplate As String)
' Opens a document in Word and inserts values from
' current record at bookmarks in Word document.
' Accepts: path to Word template file - String
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim frm As Form
Dim strAddress As String
' return reference to form
Set frm = Forms!frmAddresses
' 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, getting values from form
InsertAtBookmarks objWord, objDoc, "FirstName", frm!FirstName
InsertAtBookmarks objWord, objDoc, "LastName", frm!LastName
strAddress = (frm!Address + vbNewLine) & (frm!Address2 + vbNewLine) & _
(frm!City.Column(1) + vbNewLine) & (frm!County + vbNewLine) &
frm!PostCode
InsertAtBookmarks objWord, objDoc, "Address", strAddress
InsertAtBookmarks objWord, objDoc, "CurrentDate", Format(VBA.Date(), "d
mmmm yyyy")
InsertAtBookmarks objWord, objDoc, "ToName", frm!FirstName
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
==========================================
What I need is to be able to change the "DoCmd.PrintOut" in the 1st piece of
code so that the data on the "Print Details" form will print at a Bookmarked
location in an EXISTING Word Template.
How would I go about doing this?
Thanks in advance ...