Re: merge current form data to a new word file based on a word template



thanks for all your help Salad!! This works really well!! For
anyone else that would like a similar solution here is the code that
worked for me!

<CODE STARTS HERE>

'SAVING THE LEASELOCK DOCUMENT TO SPECIFIC FOLDER
Private Sub MergeButton2_Click()
On Error GoTo MergeButton2_Err
Dim objWord As Word.Application

Dim strTemplate As String
Dim strDoc As String

'select location of the template file
strTemplate = "X:\<full path and file name for template>.doc"
'point word to save in the following directory. below takes directory
from form field
'form field set to concetenate information to form a directory path
strDoc = "X:\Leaselocks\" & Forms!frm_Leaselocks!GetDirectory

FileCopy strTemplate, strDoc
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open (strDoc)

..ActiveDocument.Bookmarks("<name of your bookmark").Select
..Selection.Text = (CStr(Forms!<your form name>!<your field name>))
'repeat for each bookmark reference in your document

objWord.ActiveDocument.Save

objWord.Quit

End With

Exit Sub
MergeButton2_Err:
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
Else
MsgBox Err.Number & vbCr & Err.Description
End If
Exit Sub
End Sub
<CODE ENDS HERE>
.



Relevant Pages