Write Access Query to Word Bookmark
crystal (strive4peace)
Training & Development ... connect and help build dreams, MVP
See an Access query in a Word document, written after a bookmark in a pretty table.
Download the code from MsAccessGurus:
Write Access Query To Word Bookmark using VBA
STEPS
1. Make a query with the information you want in a Word table
2. Open a Word Document
3. Create a bookmark where you want the table
from ribbon: Insert, Bookmark (Links group), [enter Bookmark name] and click Add
4. CUSTOMIZE Word_QueryToTableBookmark_s4p with your query name and your bookmark name
5. compile, save, and run the code from Access
By default, your field names will be the column headings for the table. They will be shaded and marked as a header row to repeat in case the table is on more than one page.
Also by default, the table will have gray borders around data cells and black borders on the heading cells.
You can also do additional formatting on any column once the table is written by customizing and calling Word_CustomFormatColumn_s4p.
Although the code is written for you to specify query and bookmark name to run once, you could easily store bookmarks and query names in an Access table then loop and write several tables to your Word document.
If you loop, you may also want to make the table Caption a parameter. Currently, it writes the query name along with the number of rows and columns. If a caption isn't specified, it is skipped.
Something else you might like is an easy way to show or hide the bookmark indicators in your Word documents:
Toggle Bookmark Display in Word using VBA
See your Access queries in Word tables with a nice, consistent look.
kind regards, crystal
#VBA #msaccess #microsoftaccess #dev #developer #office365 #m365 #msword #query #table #borders #shading
MS Access database developer
6 个月code in demand!
Business Owner
6 个月Thank you, Crystal, for sharing these procedures. Any chance you will be making a video on this subject?