User Defined Type Not Defined

May 19, 2016
Reaction score
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

'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

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?

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question