Chr(10) does not produce linefeed in formfield

S

Steve T

Using Office XP I am populating formfields on a Word
template from a query in Access. Everything works fine,
but when I attempt to do a line-feed, all I get is a
little box. I have tried both Chr(10) and Chr(13) for
line feed and carriage return. Other Chr codes work. Chr
(36) produces a dollar sign, etc.

How can I do a line feed in a formfield with code?

Thanks in advance.

Steve
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Steve,

Use vbCr

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
S

SteveT

Thanks, Doug, but that didn't work either.
I'm thinking the problem is that I'm in a form field.

This is the code I'm using to open a Word template and
automatically populate a form field with information in
an Access recordset. The recordset is a list of
victims's names, addresses, and phone numbers. I want to
loop throught the records, giving a number to each
victim. Usually there's no more than 2 or 3, but I want
them on separate lines. This information populates a
form field called "Victims" in the Word document.
CODE:

Dim oDoc As Word.Document
Dim strVictims As String
Dim rst1 As ADODB.Recordset
Dim i As Integer
i = 1
Set rst1 = New ADODB.Recordset
rst1.Open "SELECT entryID, fullname, address,
txtphone " _
& "FROM qryVictimNames WHERE entryID = " &
Me.txtEntryID, _
CurrentProject.Connection
Do Until rst1.EOF
strVictims = strVictims & "#" & i & "-" & rst1!
FullName & " " & rst1!Address & " " & _
rst1!txtphone & Chr(10) 'or vbCR or
everything else I've tried
i = i + 1
rst1.MoveNext

Loop
rst1.Close
Set rst1 = Nothing


Set oDoc = oSupp.Documents.Add
("Z:\templates\AccessSuppRpt.dot")
With oDoc
.FormFields("victims").Result = strVictims
' Other formfields are populated similarly..
End With
oSupp.Visible = True
 
S

SteveT

I've tried vbCr and it gives me the same thing as Chr
(10), a little square box. I also tried vbKeyReturn the
VBA constant for ENTER, and that gives me the number 138
in the form field, but everything still stays on the same
line. Any ideas?

Thanks in advance..
 
S

SteveT

No, Perry, but thanks for trying. vbCrLf gave me TWO
little boxes in my string, but no linefeed.

I'm thinking it may have something to do with being in a
form field, but when I'm in the form I can start a new
line while in the field by hitting the ENTER key. But I
can't find a way to do it from code.

I also tried vbKeyReturn the VBA constant for the ENTER
key, and that returned a "13" in the string. ?????
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Steve,

I am sure that it is not because of your trying to insert it into a
formfield because if a macro containing the following code is run on exit
from the formfield "Text1", the result is

lineone¶
linetwo

Instead of trying to build a string containing all of the records, you may
need to create the document and populate the formfield by using


Do Until rst1.EOF
If oDoc.FormFields("victims").Result = "" then
odDoc.FormFields("victims").Result = strVictims & "#" & i & "-" &
rst1!FullName & " " & rst1!Address & " " & rst1!txtphone
Else
odDoc.FormFields("victims").Result =
odDoc.FormFields("victims").Result & vbCr &strVictims & "#" & i & "-" &
rst1!FullName & " " & rst1!Address & " " & rst1!txtphone
End If
i = i + 1
rst1.MoveNext
Loop


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
S

SteveT

Thanks, Doug, for your suggested code. It was a
different way of doing this, but produced the same
results. With two victims in my data base, your
suggested code put them both on the same line.

In frustration,
Steve
 
S

SteveT

I just noticed something peculiar, Doug.
After I populate the Word document, using your code, the
result with two records is the first string, a small box,
then the second string--all on one line.

If I put the cursor in front of the small box character
and hit ENTER, the second string moves down TWO lines and
the little box disappears.

In other words, the line feed is there, it just doesn't
activate. When I place another one in manually, the
first one activates as well.

On a whim I formatted the field to calculate on exit, but
that didn't help.

I think we're dealing with a bug.

What do you think?

Steve
 
L

Lars-Eric Gisslén

Steve,

Use Chr(11)

--
Regards,
Lars-Eric Gisslén

"SteveT" <[email protected]> skrev i meddelandet
Thanks, Doug, for your suggested code. It was a
different way of doing this, but produced the same
results. With two victims in my data base, your
suggested code put them both on the same line.

In frustration,
Steve
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Steve,

Not having your database to use, I set up a document with a couple of
formfields with one of them having the bookmark name of victioms and had a
macro containing the following code run on exit from that formfield.

Dim i As Long, oDoc As Document
Set oDoc = ActiveDocument
For i = 1 To 10
If oDoc.FormFields("victims").Result = "" Then
oDoc.FormFields("victims").Result = "Item" & i
Else
oDoc.FormFields("victims").Result =
oDoc.FormFields("victims").Result & vbCr & "Item" & i
End If
Next i

It populated the formfield with

Item1¶
Item2¶
....
....
Item10¶

That was after I corrected the couple of typos in the code that I had
suggested (oDoc and odDoc)
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
I just noticed something peculiar, Doug.
After I populate the Word document, using your code, the
result with two records is the first string, a small box,
then the second string--all on one line.

If I put the cursor in front of the small box character
and hit ENTER, the second string moves down TWO lines and
the little box disappears.

In other words, the line feed is there, it just doesn't
activate. When I place another one in manually, the
first one activates as well.

On a whim I formatted the field to calculate on exit, but
that didn't help.

I think we're dealing with a bug.

What do you think?

Steve
 
S

SteveT

Lars-Eric, You are my hero. I've never heard of a
vertical tab before, but it works.

I owe you a beer!

Steve
 
S

SteveT

Doug--
Thanks for you efforts, I know you spent some time on my
problem. It may have something to do with sending the
code from an MS Access form. Nothing worked until I
tried the vertical tab, Chr(11), as suggested by Lars-
Eric.

Steve
 
J

JGM

Hi Steve,

It is probably because the people at MS decided to include a little comment
in the online help file, somehting to the effect that Chr(11) is not managed
under Microsoft Windows. At least this is what it says in my online help, on
the page that lists the character codes from 0 to 127.

I never used it because I though it was useless to even try, until someone
suggested I gave it a shot a while back... it might have been Lars!

Cheers!

--
_______________________________________
Jean-Guy Marcil
(e-mail address removed)

"SteveT" <[email protected]> a écrit dans le message de [email protected]...
Doug--
Thanks for you efforts, I know you spent some time on my
problem. It may have something to do with sending the
code from an MS Access form. Nothing worked until I
tried the vertical tab, Chr(11), as suggested by Lars-
Eric.

Steve
 

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