Results 1 to 6 of 6
  1. #1
    edi dhar is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    3

    Populate Word Userform with data from Access

    Hi,



    I'm hoping someone can help with a problem i have as I am completely stumped. First off I guess I need to know if it is possible to do what I am trying to do and secondly if anyone can provide any help.

    I am trying to populate a userform in MS Word with data from an MS Access userform. The idea being a user will look at the database and pick a record that will open up in the userform that appears when the MS Word template opens. I have been working on this for the past 2 days and I am able to send data to a word document and populate either formfields or bookmarks but the letter templates I've been given to work with come with a userform and they have to stay as the users require them to complete a few more fields not available in the Access database and there's other bits of VBA code that is contained within the userform.

    Any help would be gratefully appreciated...even if that's just to say what I'm trying to achieve isn't possible.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Response number three, marked as answer, seems to be a good description of how to populate Word doc form fields.
    http://stackoverflow.com/questions/1...tion-through-w

  3. #3
    edi dhar is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    3
    Hi ItsMe,

    Thank for you for the quick response however i don't think that option works for me. I'm trying to populate a userform in Word not formfields on a word document. I don't even know if this is possible as i can't find anything on it. All the help out there points to using bookmarks, formfields, or using DAO/ADO within the word document to return data from the database. All of which i am able to do but the scope i've been given requires me to populate the existing userform within the word template.

    Cheers

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Hmm, was not aware of this userform thing....

    I found this, which supposedly creates the bookmarks in a word form. I am not sure it populates the text though. It seems that the idea of a userform is to collect data from user input. So not any support for supplementing the User Input action or replacing the User Input action via Automation.
    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx


    You may already have seen this.
    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

    I created some air code here. But not seeing any Text property or way to write to the Bookmark. It seems to be read only.

    Code:
    Dim myWordApp As Word.Application
    Dim docNew As Word.Document
    Dim docBookmark As Word.Bookmark
    Set myWordApp = CreateObject("Word.Application")
    myWordApp.Visible = True
    Set docNew = myWordApp.Documents.Open("C:\Test\SampleDoc.docx")
        
        For Each docBookmark In docNew.Bookmarks
        
            Debug.Print docBookmark.Name
        
        Next
    docNew.Close
    myWordApp.Quit
    Set docNew = Nothing
    Set myWordApp = Nothing

  5. #5
    edi dhar is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    3
    Yeah unfortunately the userform is non negotiable and has to be included as part of my solution. I have a compromise where i populate the bookmarks on the word template then call the userform within the word document to then pick up the bookmarks during form load. This will work (I think) but it's not very clean and would be much better if i can send data straight to userform.

    The code i have for populating the bookmarks is something like below.

    Dim appword As Word.Application
    Dim doc As Word.Document


    Set appword = GetObject(, "Word.Application")
    Set appword = New Word.Application

    Set doc = appword.Documents.Open("C:\Test\SampleDoc.docx
    ", , True)

    With doc
    .Bookmarks("word_bookmark").Range = Me!Access_Field
    .Visible = True
    .Activate
    End with


    Thanks for you effort so far. Those links a quite good and could prove to be handy.

    Cheers

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    This looks like your solution right here
    .Bookmarks("word_bookmark").Range = Me!Access_Field

    All you need to do is get the names of your bookmarks using the code snippet I provided (and provided the code I provided iterates your doc). With that, you can use a DAO Recordset to populate the bookmark using the Document's Bookmark collection and the .Range property.

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

Similar Threads

  1. Using Access Data in Word Doc
    By Jacob.T in forum Import/Export Data
    Replies: 2
    Last Post: 07-26-2014, 07:10 AM
  2. Word VBA Data from Access
    By JulieK in forum Programming
    Replies: 14
    Last Post: 07-03-2014, 03:40 AM
  3. Replies: 3
    Last Post: 05-22-2013, 01:50 PM
  4. Transfer data from access to word
    By TOMMY.MYERS668 in forum Programming
    Replies: 11
    Last Post: 02-23-2013, 08:45 AM
  5. Replies: 1
    Last Post: 03-18-2011, 03:22 PM

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