bwyrwitzke
Registered User.
- Local time
- Today, 15:43
- Joined
- Nov 11, 2002
- Messages
- 50
Another MailMerge question for you…
I have a main form with multiple subforms, and in one case a nested subform that I’m attempting to export to MS Word using a slightly modified version of the MailMerge code that I found on this forum. So far, everything is progressing well, but I’m hung up on my attempt to pass ALL of the subform (and nested subform) records to Word.
Here’s the current code that I’m using:
Any suggestions would be greatly appreciated. Thanks.
I have a main form with multiple subforms, and in one case a nested subform that I’m attempting to export to MS Word using a slightly modified version of the MailMerge code that I found on this forum. So far, everything is progressing well, but I’m hung up on my attempt to pass ALL of the subform (and nested subform) records to Word.
Here’s the current code that I’m using:
Code:
Private Sub cmdSend_Click()
' Check for empty fields and unsaved record.
If Me.Dirty Then
If MsgBox("Record has not been saved. " & Chr(13) & _
"Do you want to save it?", vbInformation + vbOKCancel) = vbOK Then
DoCmd.RunCommand acCmdSaveRecord
Else
Exit Sub
End If
End If
' Create a Word document from template.
Dim WordApp As Word.Application
Dim strTemplateLocation As String
' Specify location of template
strTemplateLocation = "C:\resumes\template1.dot"
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
End If
On Error GoTo ErrHandler
WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
' Replace each bookmark with field contents.
With WordApp.Selection
'data from main form
.Goto what:=wdGoToBookmark, Name:="name"
.TypeText (name_first & " " & name_last)
.Goto what:=wdGoToBookmark, Name:="summary"
.TypeText [experience_summary]
.Goto what:=wdGoToBookmark, Name:="certifications"
.TypeText [certifications]
.Goto what:=wdGoToBookmark, Name:="clearance"
.TypeText [clearance]
'data from subfrmEducation
.Goto what:=wdGoToBookmark, Name:="degree"
.TypeText Me!subfrmEducation.Form!degree
.Goto what:=wdGoToBookmark, Name:="school"
.TypeText Me!subfrmEducation.Form!school
.Goto what:=wdGoToBookmark, Name:="yrs_attended"
.TypeText Me!subfrmEducation.Form!yrs_attended
'data from subfrmEmploymentHistory
.Goto what:=wdGoToBookmark, Name:="employer"
.TypeText Me!subfrmEmploymentHistory.Form!employer
.Goto what:=wdGoToBookmark, Name:="employer_location"
.TypeText Me!subfrmEmploymentHistory.Form!employer_location
.Goto what:=wdGoToBookmark, Name:="title"
.TypeText Me!subfrmEmploymentHistory.Form!Title
.Goto what:=wdGoToBookmark, Name:="date_start"
.TypeText Me!subfrmEmploymentHistory.Form!date_start
.Goto what:=wdGoToBookmark, Name:="date_end"
.TypeText Me!subfrmEmploymentHistory.Form!date_end
'data from nested subfrmProjects
.Goto what:=wdGoToBookmark, Name:="project_title"
.TypeText Me!subfrmEmploymentHistory.Form!subfrmProjects.Form!project_title
.Goto what:=wdGoToBookmark, Name:="project_description"
.TypeText Me!subfrmEmploymentHistory.Form!subfrmProjects.Form!project_description
'data from subfrmPublications
.Goto what:=wdGoToBookmark, Name:="pub_author"
.TypeText Me!subfrmPublications.Form!pub_author
.Goto what:=wdGoToBookmark, Name:="pub_title"
.TypeText Me!subfrmPublications.Form!pub_title
.Goto what:=wdGoToBookmark, Name:="pub_forum"
.TypeText Me!subfrmPublications.Form!pub_forum
.Goto what:=wdGoToBookmark, Name:="pub_date"
.TypeText Me!subfrmPublications.Form!pub_date
End With
DoEvents
WordApp.Activate
Set WordApp = Nothing
Exit Sub
ErrHandler:
Set WordApp = Nothing
End Sub
Any suggestions would be greatly appreciated. Thanks.