A family of Microsoft relational database management systems designed for ease of use.
Select Tools > References... in the Visual Basic Editor.
Tick the check box for 'Microsoft Word 16.0 Object Library'.
Click OK.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This module literally worked fantastically yesterday. In the meantime I upgraded my Access subscription to Office 365 Business and had to have Access reinstalled. I am now getting the error "Compile error User Defined Type not defined" on a module that merges access data to a word document. Here is the code:
Public Sub ExportDatatoEASETemplate()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Set wApp = New Word.Application
Set wDoc = wApp.Documents.Open("C:\Users\Robert\Documents\MPN\Proposal Template.docx")
Set rs = CurrentDb.OpenRecordset("qryFirstNationalForm")
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
wDoc.Bookmarks("CorporateName").Range.Text = Nz(rs!CorporateName, "")
wDoc.Bookmarks("Address1").Range.Text = Nz(rs!Address1, "")
wDoc.Bookmarks("Address2").Range.Text = Nz(rs!Address2, "")
wDoc.Bookmarks("City").Range.Text = Nz(rs!City, "")
wDoc.Bookmarks("Province").Range.Text = Nz(rs!Province, "")
wDoc.Bookmarks("PostalCode").Range.Text = Nz(rs!PostalCode, "")
wDoc.SaveAs2 "C:\Users\Robert\Documents\MPN" & rs!FirstNationalID & "_Proposal Template.docx"
wDoc.Bookmarks("CorporateName").Range.Delete wdCharacter, Len(Nz(rs!CorporateName, ""))
wDoc.Bookmarks("Address1").Range.Delete wdCharacter, Len(Nz(rs!Address1, ""))
wDoc.Bookmarks("Address2").Range.Delete wdCharacter, Len(Nz(rs!Address2, ""))
wDoc.Bookmarks("City").Range.Delete wdCharacter, Len(Nz(rs!City, ""))
wDoc.Bookmarks("Province").Range.Delete wdCharacter, Len(Nz(rs!Province, ""))
wDoc.Bookmarks("PostalCode").Range.Delete wdCharacter, Len(Nz(rs!PostalCode, ""))
rs.MoveNext
Loop
wDoc.Close False
wApp.Quit
Set wDoc = Nothing
Set wApp = Nothing
Set rs = Nothing
End Sub
A family of Microsoft relational database management systems designed for ease of use.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Select Tools > References... in the Visual Basic Editor.
Tick the check box for 'Microsoft Word 16.0 Object Library'.
Click OK.
Also set a reference to DAO:
If your database is a .mdb database, it is the Microsoft DAO 3.6 Object Library.
If your database is a .accdb database, it is the Microsoft Office 16.0 Access database engine Object Library.
Solved it Hans - had to add Microsoft DAO to references. Thanks for your help!!
Rob