How to format mergefield dates and numbers within VBA code

P

Philip Lages

Hi,

I use this code to insert mergefields filled by an Access DB into a
document .

ActiveDocument.FormFields("txtWerkNaam").Select
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range,
Name:="naam_werk"

This works fine but the contents of the date fields are formatted dd/MM/yyy
H/mm/ss
I don't want to disply the time in my document.
How can i format mergefields in VBA

Any help appreciated

Philip Lages
 
D

Doug Robbins

Hi Philip,

Use the following code to insert the mergefield with a formatting switch:

Dim myrange As Range
Set myrange = ActiveDocument.FormFields("txtWerkNaam").Range
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldEmpty,
Text:="mergefield txtWerkNaam \@ ""dd MM yyyy"""


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
P

Philip Lages

Thanks Doug this works perfectly

Philip Lages

Doug Robbins said:
Hi Philip,

Use the following code to insert the mergefield with a formatting switch:

Dim myrange As Range
Set myrange = ActiveDocument.FormFields("txtWerkNaam").Range
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldEmpty,
Text:="mergefield txtWerkNaam \@ ""dd MM yyyy"""


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top