Results 1 to 2 of 2
  1. #1
    nklint52696 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jul 2017
    Posts
    1

    Exclamation Code that exports database data to a bookmarked MS word Template (.dot)

    I am extremely new to VB code and Access but I have been tasked with creating a command button within a database that holds multiple records. Each record should have the ability to export their specific data entries to a report that contains lots of formatting. I figured a .dot template with bookmarks would be the best way to get the design and function that is necessary. So far all I have found is various simple codes but every time I try to initiate the code it doesn't work. Below is what I have so far. When I click the cmd button word does not open. This database is linked through an online accessible server and I did not know if there were restrictions to what those types of databases could and couldn't do.



    Sub Command516_Click()
    Dim WordDoc As Word.Document
    Dim WordApp As Word.Application
    Dim comboID As String
    Dim sn As String
    Dim frb_report As String

    set WordApp=Word.Application
    WordApp.Visible=True

    set strTemplate=Word.Document.Open("C:......Template.d ot")
    Set WordDoc= WordApp.Documents.Add(Template:=strTemplate)

    comboID=Forms!frmviewedit!comboID
    sn=Forms!frmviewedit!sn
    frb_report=Forms!frmviewedit!frb_report

    Debug.Print WordDoc.Bookmarks.Count 'show test presence of bookmarks'

    With WordDoc.Bookmarks
    .Item("frb_id").Range.Text=comboID
    .Item("serial_no0").Range.Text=sn
    .Item("report_no").Range.Text=frb_report

    End With

    WordDoc.Save
    WordDoc.close
    Set WordDoc=Nothing
    WordApp.Quit
    Set WordApp=Nothing

    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have never use Access to automate MS Word, but you might check out the links I found and posted
    https://www.accessforums.net/showthr...highlight=word



    Good luck....

Please reply to this thread with any new information or opinions.

Similar Threads

  1. MS Word template with bookmarks
    By jonnyh in forum Import/Export Data
    Replies: 2
    Last Post: 09-07-2016, 07:42 AM
  2. Populate Word template with data from textbox
    By Kevo in forum Database Design
    Replies: 2
    Last Post: 10-18-2014, 07:57 AM
  3. Replies: 5
    Last Post: 06-23-2014, 08:54 AM
  4. Replies: 5
    Last Post: 02-01-2013, 11:36 AM
  5. vba code to populat word template in Access 2010
    By graffjohn in forum Programming
    Replies: 2
    Last Post: 06-11-2011, 09:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums