jpkeller55
Technical User
Clearly I am a novice at this and need help. I am trying to utilize the code listed in faq702-2379 to populate data from an Access form to a Word document. I am using 2002 version of Access and Word. Code so far:
First I am getting a message that states: Compile error:User-defined type not defined. Also, the code in Red is in red in the VBA editor window. Can anybody lend some help to get me on track?
Thanks, jpkeller55
Code:
Public Function CreateWordLetter(strDocPath As String)
If IsNull(strDocPath) Or strDocPath = "" Then
Exit Function
End If
Dim dbs As Database
Dim objWord As Object
Dim PrintResponse
Set dbs = CurrentDb
'create reference to Word Object
Set objWord = CreateObject("Word.Application")
'Word Object is created - now let's fill it with data.
With objWord
.Visible = True
.Documents.Open (strDocPath)
'move to each bookmark, and insert correct text.
[COLOR=red].ActiveDocument.Bookmarks("FN".Select][/color]
.Selection.Text = (CStr(Forms!NamesFrm!FirstName))
[COLOR=red].ActiveDocument.Bookmarks.Add Name:=FN,[/color]
Range = Selection.Range
'continue the ActiveDocument and Selection statements for each bookmark that you have on the Word Document **
End With
'find out if the user would like to print the document
'at this time.
PrintResponse = MsgBox("Print this document?", vbYesNo)
If PrintResponse = vbYes Then
objWord.ActiveDocument.PrintOut Background:=False
End If
'release all objects
Set objWord = Nothing
Set dbs = Nothing
End Function
Thanks, jpkeller55