Results 1 to 8 of 8
  1. #1
    christosf360 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2024
    Posts
    3

    Macro to open Word document with bookmarks issue

    Hello everyone, very new to Access.



    I am trying to create a button that will run a macro and this macro needs to open up a Word file and use bookmarks to copy and paste some of the data from the Access database (people's names, addresses etc) into the Word document. I am using the code below to open the Word document but it fails. The computer is trying to open it but eventually nothing happens and no errors occur either.

    I did go into VBA and into References and I linked with the Word Object Library. I also need to say that in our organisation we are using Microsoft Teams for file storage so in the code below, the path is a link pasted from Teams. I believe that the path is accurate because the code doesn't produce any errors, the computer tries to open the file for a second or two and than it stops and nothing happens. Any advice please?...?

    Code:
    Dim wApp As Word.Application
    Dim wDoc As Word.Document
    
    Set wApp = New Word.Application
    Set wDoc = wApp.Documents.Open("path/FileName.docx")

  2. #2
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    try Albert's Super easy word merge. http://www.kallal.ca/msaccess/msaccess.html
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    madpiet is online now Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    156
    you only need VBA if you're doing something outside the bounds of what a regular mail merge will do... in other words, merge a single record at a time from a table or query in your database to a single document. So you get one document per record in your dataset. If you need something like all the child records of some parent record to be included too (like an invoice), then you need to use bookmarks or similar, because then you need to merge in the parent records and then insert and expand the child data to a table in your Word document. But this sounds like the simple version.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430

    I believe that the path is accurate because the code doesn't produce any errors

    Set wDoc = wApp.Documents.Open("path/FileName.docx")
    Is that really your code? If so you don't have a drive, the folder is called 'path' and the name of the file is 'filename'

  5. #5
    christosf360 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2024
    Posts
    3
    Quote Originally Posted by CJ_London View Post
    Is that really your code? If so you don't have a drive, the folder is called 'path' and the name of the file is 'filename'
    No, this isn't the path, the real path has a drive and a proper file name.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,945
    Quote Originally Posted by christosf360 View Post
    Hello everyone, very new to Access.

    I am trying to create a button that will run a macro and this macro needs to open up a Word file and use bookmarks to copy and paste some of the data from the Access database (people's names, addresses etc) into the Word document. I am using the code below to open the Word document but it fails. The computer is trying to open it but eventually nothing happens and no errors occur either.

    I did go into VBA and into References and I linked with the Word Object Library. I also need to say that in our organisation we are using Microsoft Teams for file storage so in the code below, the path is a link pasted from Teams. I believe that the path is accurate because the code doesn't produce any errors, the computer tries to open the file for a second or two and than it stops and nothing happens. Any advice please?...?

    Code:
    Dim wApp As Word.Application
    Dim wDoc As Word.Document
    
    Set wApp = New Word.Application
    Set wDoc = wApp.Documents.Open("path/FileName.docx")
    That appears to open with a default path?

    What are you expecting to happen?, that the word document will come to the foreground?
    Attached Thumbnails Attached Thumbnails Capture.JPG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    christosf360 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2024
    Posts
    3
    Quote Originally Posted by Welshgasman View Post
    That appears to open with a default path?

    What are you expecting to happen?, that the word document will come to the foreground?
    I was expecting the word document to open, isn't that what the Open.file command would do?

    When the Word document is open, I would like to use bookmarks to copy and paste data from Access into the Word template. Am I doing it wrong?...?

    Thanks

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,945
    It will open hidden unless you set the Visible property to true.

    Have you tried Google?, that is always my first point of call.

    https://www.google.com/search?q=acce...hrome&ie=UTF-8
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 1
    Last Post: 07-26-2017, 01:25 PM
  2. Replies: 1
    Last Post: 01-24-2014, 01:21 PM
  3. Replies: 3
    Last Post: 02-22-2013, 06:41 AM
  4. Replies: 1
    Last Post: 03-18-2011, 03:22 PM
  5. Open a word document from access
    By natalia in forum Programming
    Replies: 1
    Last Post: 10-13-2010, 08:04 AM

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