How to retain original table format when updating a DATABASE field code in Word 2010

I want to create a Word 2010 document that contains a DATABASE field code to fetch some query result. I inserted that field code using "Insert / Quick Parts". Since the query generates many lines and columns, it ends up as a table in the document. Fine. That's what I want. Then, I created a VBA macro to prompt the user (on Document.Open) to enter a certain value, and then the macro uses that value to update the DATABASE field code to refresh the query results. I tested it and it works fine. Then I formatted the table generated by the DATABASE field code (column headings a certain color, thick border, blah, blah...), and saved the document. When I reopen the document, an InputBox pops up as expected and asks for a value, the macro updates the SQL query in the Text property of the field code object, the data is fetched, the table is updated, but all formatting is lost, even if I specify the "\* MERGEFORMAT" switch inside the DATABASE field code.

What am I doing wrong?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


you have to create a table style from your table then use it with the switches

\l "20" \b "511"

see for reference


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
J2015Author Commented:

Just one comment: these 2 switches do not replace the "\* MERGEFORMAT" switch, they complement it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.