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
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