Underlining, padding, trailing spaces

D

Dick Kusleika

I'm creating a contract where data will be entered into an Access form and,
via automation, the data will be inserted into pre-defined bookmarks in the
Word doc. I was having trouble padding the strings and getting the
underlines to look right. I fixed all but one of the problems by making
tables and bordering the cells instead of underlining the text.

I have one piece that I can't figure out what to do. On the doc, it's
twelve lines that consist of underscores and a paragraph mark to simulate
the lines in which you would write the description of the work to be
performed. I want those twelve lines to show whether the text fills them or
not.

I tried padding the string with spaces to make it 1066 characters long, but
that presented two problems. First, the spaces continued out to the right
beyond the margins, i.e. they didn't wrap like I thought they would.
Second, because I'm not using a mono-space font, the 1066 is never going to
be exactly the right number. A side problem was that trailing spaces
weren't underlined. I can't figure out how to set that option (Tools -
Options - Customize) in code. I also thought of using a non-breaking space
to pad it, but the ascii code seems to be the same (32) for spaces and
non-breaking spaces, so I didn't know how to do that in Access VBA. I think
because of the first two problems, these last issues are moot.

I thought I would try to use a one column x 12 row table, but how would I
know where to split the text so that it flows properly from one line to the
next (the whole non-monospaced font thing again)? The tables with the
borders worked so nicely with the other fields, that I was hoping to find a
solution that uses them, but I'll take anything.

Does anyone have any suggestions on how I can keep those underlines in tact
while placing the text there?

Here's the code I'm using to replace the bookmarks and pad the text. I'm
happy to provide the rest of the code behind the Access form, I just didn't
think it would help.

Thanks

Sub UpdateBM(ByRef wdDoc As Word.Document, ByVal BMName As String, _
ByVal NewText As String)

Dim wdRange As Word.Range
Dim i As Long
Dim InTable As Long

Set wdRange = wdDoc.Bookmarks(BMName).Range

wdRange.Text = NewText
wdDoc.Bookmarks.Add BMName, wdRange

On Error Resume Next
InTable = wdRange.Cells.Count

If Err.Number > 0 Then
wdRange.Underline = wdUnderlineSingle
End If

Err.Clear
On Error GoTo 0

End Sub

Function PadText(ByVal OldText As String, ByVal PadAmt As Long) As String

Dim i As Long
Dim AddPad As Long

If PadAmt > Len(OldText) Then
AddPad = PadAmt - Len(OldText)

For i = 1 To AddPad
OldText = OldText & " "
Next i
End If

PadText = OldText

End Function
 
C

Cindy Meister -WordMVP-

Hi Dick,
I have one piece that I can't figure out what to do. On the doc, it's
twelve lines that consist of underscores and a paragraph mark to simulate
the lines in which you would write the description of the work to be
performed. I want those twelve lines to show whether the text fills them or
not.
I tried padding the string with spaces to make it 1066 characters long, but
that presented two problems. First, the spaces continued out to the right
beyond the margins, i.e. they didn't wrap like I thought they would.
Tools/Options/Compatibility: Wrap trailing spaces to next line
Second, because I'm not using a mono-space font, the 1066 is never going to
be exactly the right number.
Hmmm. Do you really have to create this part on-the-fly? You can't have a
template to use as the starting point?

My feeling is to use a grouped drawing for the lines. Or a table in a text
box. In either case, positioned behind the text and anchored to the first
paragraph of any possible text going into the 12 lines, and formatted to move
with the text. You can do this on-the-fly, anyway, it's just trickier to learn
how to get the drawing object all to do what you need them to do...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
C

Cindy Meister -WordMVP-

Hi Dick,
Do you have to use Selection? It is considered bad programming in Excel,
No, it's as "bad" in Word as in Excel. There are some cases when you have
to use it, but generally RANGE is better.
It doesn't like
Bookmarks("\line") when Bookmarks is qualified with a Range object, for
instance.
However, when you work with "line", you have no other choice. This is
because a "line" is not an object, as a paragraph is. A paragraph has a
very definite beginning and end. Think of a "line" of text in an Excel
cell: depending on how wide the cell is, the text will break here, or it
will break there. Same problem for Word.
Does Selection not work when the Application isn't visisble?
Not very well, no. Word depends on being able to physically lay things
out, on-screen. Turning of screenupdating should help, a bit. But with
"line"...
Where is Bookmarks("\line") documented in help? I couldn't find it.
Why don't they have a Lines collection? OK, that one maybe rhetorical.
<G>Discussed above. Word doesn't have a "page" object, either.

\Line is a really OLD WordBasic-bookmark thingy (think of xlm macros).
That's why you can't find it in Help. And it's even sort of an
after-thought in the old Word Developer's Kit. Really useful, like
GetDocument(50) & co. in Excel. But if you didn't "grow up" with it, you
won't know about it...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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