- Joined
- May 19, 2016
- Messages
- 1
- Reaction score
- 0
I am trying to populate a Word document from Access with this code, but keep getting a compile error.
Private Sub Print_Opportunity_Click()
Dim WordApp As word.Application
Dim WordDoc As word.Document
On Error Resume Next
Err.Clear
'Set WordApp object variable to running instance of Word.
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn’t open, create a new instance of Word.
Set WordApp = New word.Application
End If
Set WordDoc = WordApp.Documents.Open("S:\Public\Opportunities\Opportunities Tracking.docx", , True)
With WordDoc
.FormFields("fldOppID").Result = Me.ID
.FormFields("fldFirstName").Result = Me.First_Name
.FormFields("fldLastName").Result = Me.Last_Name
.FormFields("fldJobTitle").Result = Me.Job_Title
.FormFields("fldBusinessPhone").Result = Me.Business_Phone
.FormFields("fldEmail").Result = Me.Email
.FormFields("fldCompany").Result = Me.Company
.FormFields("fldAddress").Result = Me.Address
.FormFields("fldCity").Result = Me.City
.FormFields("fldState").Result = Me.State
.FormFields("fldPostalCode").Result = Me.Postal_Code
.FormFields("fldWebPage").Result = Me.Web_Page
.FormFields("fldNotes").Result = Me.Notes
.Visible = True
.Activate
End With
Set WordDoc = Nothing
Set WordApp = Nothing
Exit Sub
I have Microsoft DAO 3.6 Object Library and Microsoft ActiveX Data Objects 6.0 Library checked in References, but keep getting stopped at the Dim statements. What am I missing?
Private Sub Print_Opportunity_Click()
Dim WordApp As word.Application
Dim WordDoc As word.Document
On Error Resume Next
Err.Clear
'Set WordApp object variable to running instance of Word.
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn’t open, create a new instance of Word.
Set WordApp = New word.Application
End If
Set WordDoc = WordApp.Documents.Open("S:\Public\Opportunities\Opportunities Tracking.docx", , True)
With WordDoc
.FormFields("fldOppID").Result = Me.ID
.FormFields("fldFirstName").Result = Me.First_Name
.FormFields("fldLastName").Result = Me.Last_Name
.FormFields("fldJobTitle").Result = Me.Job_Title
.FormFields("fldBusinessPhone").Result = Me.Business_Phone
.FormFields("fldEmail").Result = Me.Email
.FormFields("fldCompany").Result = Me.Company
.FormFields("fldAddress").Result = Me.Address
.FormFields("fldCity").Result = Me.City
.FormFields("fldState").Result = Me.State
.FormFields("fldPostalCode").Result = Me.Postal_Code
.FormFields("fldWebPage").Result = Me.Web_Page
.FormFields("fldNotes").Result = Me.Notes
.Visible = True
.Activate
End With
Set WordDoc = Nothing
Set WordApp = Nothing
Exit Sub
I have Microsoft DAO 3.6 Object Library and Microsoft ActiveX Data Objects 6.0 Library checked in References, but keep getting stopped at the Dim statements. What am I missing?