Formatting fields text

M

MaxBass #I-D

Hi.
I have the following problem: I've inserted a database field inside a
document.
The result is a number, say 1500100.27
I need to expose it with the thousands separator, such as, for example
1,500,100.27

I haven't found anything to do that neither with the word commands nor
via VBA.
Any suggestion?
 
Z

Zoonotics

I only know that in Excel, you select the number and format it as a
number and you have a choice to use the commas or not.
 
M

MaxBass #I-D

I only know that in Excel, you select the number and format it as a
number and you have a choice to use the commas or not.

I knew it in Excel too.
Unfortunately I need it in Word; if Word doesn't allow this I have to
find another way.
Thanks anyway.
 
M

MaxBass #I-D

Hi.
I have the following problem: I've inserted a database field inside a
document.
The result is a number, say 1500100.27
I need to expose it with the thousands separator, such as, for example
1,500,100.27

I haven't found anything to do that neither with the word commands nor
via VBA.
Any suggestion?

Finally I did it.
To format a field result the fields switches has to be used.
But there is not (or at least I didn't find) the "plug" for the
switches in the object model of the database field.
The only way I found was the following.

First insert the database field (i.e.)

Selection.Range.InsertDatabase Format:=wdTableFormatNone, Style:=0,
LinkToSource:=True, Connection:= "...."

Then adding the switch (i.e.)

Set lField = ActiveDocument.Fields(ActiveDocument.Fields.Count)
s = lField.Code
If Right(s, 26) <> CMASK Then
s = s & " " & CMASK
lField.Code.Text = s
lField.Update
End If

CMASK is the switch and is defined, for my needs, as follows.

Const CMASK As String = "\# ""#.###,00;(#.###,00);0"""

The "IF" only checks if the switch has already been appended.
The lField.Update is required to apply the switch and have the desired
layout; this unfortunately means that a double query should be executed
to have the final mask.

For me this works fine.
If anyone finds a better way it would be welcome.

Regards.
 

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