{"id":2772,"date":"2013-01-11T03:20:59","date_gmt":"2013-01-11T03:20:59","guid":{"rendered":"http:\/\/nycphantom.com\/journal\/?p=2772"},"modified":"2017-06-02T17:05:11","modified_gmt":"2017-06-02T21:05:11","slug":"exporting-ms-access-data-into-ms-word","status":"publish","type":"post","link":"http:\/\/nycphantom.com\/journal\/?p=2772","title":{"rendered":"Exporting MS Access data into MS Word"},"content":{"rendered":"<p><a href=\"http:\/\/www.techrepublic.com\/blog\/msoffice\/how-do-i-fill-word-form-fields-with-access-data\/164\" target=\"_blank\" rel=\"noopener noreferrer\">Finally<\/a>, there is an easy way(filling MS Word <span style=\"color: #ff0000;\">fields<\/span> with Access <span style=\"color: #339966;\">data<\/span>) in Access using VBA scripting:<\/p>\n<p><em>Private Sub cmdPrint_Click()<\/em><br \/>\n<em>'Print customer slip for current customer.<\/em><br \/>\n<em>Dim appWord As Word.Application<\/em><br \/>\n<em>Dim doc As Word.Document<\/em><br \/>\n<em>'Avoid error 429, when Word isn't open.<\/em><br \/>\n<em>On Error Resume Next<\/em><br \/>\n<em>Err.Clear<\/em><br \/>\n<em>'Set appWord object variable to running instance of Word.<\/em><br \/>\n<em>Set appWord = GetObject(, \"Word.Application\")<\/em><br \/>\n<em>If Err.Number &lt;&gt; 0 Then<\/em><br \/>\n<em>'If Word isn't open, create a new instance of Word.<\/em><br \/>\n<em>Set appWord = New Word.Application<\/em><br \/>\n<em>End If<\/em><br \/>\n<em>Set doc = appWord.Documents.Open(\"C:\\WordForms\\CustomerSlip.doc\", , True)<\/em><br \/>\n<em>With doc<\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldCustomerID<\/span>\").Result = <span style=\"color: #339966;\">Me!CustomerID<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldCompanyName<\/span>\").Result = <span style=\"color: #339966;\">Me!CompanyName<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldContactName<\/span>\").Result = <span style=\"color: #339966;\">Me!ContactName<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldContactTitle<\/span>\").Result = <span style=\"color: #339966;\">Me!ContactTitle<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldAddress<\/span>\").Result = <span style=\"color: #339966;\">Me!Address<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldCity<\/span>\").Result = <span style=\"color: #339966;\">Me!City<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldRegion<\/span>\").Result = <span style=\"color: #339966;\">Me!Region<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldPostalCode<\/span>\").Result = <span style=\"color: #339966;\">Me!PostalCode<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldCountry<\/span>\").Result = <span style=\"color: #339966;\">Me!Country<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldPhone<\/span>\").Result = <span style=\"color: #339966;\">Me!Phone<\/span><\/em><br \/>\n<em>.FormFields(\"<span style=\"color: #ff0000;\">fldFax<\/span>\").Result = <span style=\"color: #339966;\">Me!Fax<\/span><\/em><br \/>\n<em>.Visible = True<\/em><br \/>\n<em>.Activate<\/em><br \/>\n<em>End With<\/em><br \/>\n<em>Set doc = Nothing<\/em><br \/>\n<em>Set appWord = Nothing<\/em><br \/>\n<em>Exit Sub<\/em><br \/>\n<em>errHandler:<\/em><br \/>\n<em>MsgBox Err.Number &amp; \": \" &amp; Err.Description<\/em><br \/>\n<em>End Sub<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Finally, there is an easy way(filling MS Word fields with Access data) in Access using VBA scripting: Private Sub cmdPrint_Click() 'Print customer slip for current customer. Dim appWord As Word.Application Dim doc As Word.Document 'Avoid error 429, when Word isn't &hellip; <a href=\"http:\/\/nycphantom.com\/journal\/?p=2772\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2772","post","type-post","status-publish","format-standard","hentry","category-technical"],"_links":{"self":[{"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/2772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2772"}],"version-history":[{"count":7,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/2772\/revisions"}],"predecessor-version":[{"id":7573,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/2772\/revisions\/7573"}],"wp:attachment":[{"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2772"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}