Connecting Tech Pros Worldwide Forums | Help | Site Map

Text box question

Access User
Guest
 
Posts: n/a
#1: Nov 13 '05
This seems like it should be easy, but I can't find the answer anywhere.
I need to combine text fields from several different records into one
text box for display purposes. Here's the code I'm using: (rstTable is
a recordset)

do until rstTable.EOF
txtBox.text = txtBox.text & rstTable!Description & chr(13)
rstTable.MoveNext
Loop

The problem is the text box ignores the carriage returns. I get all the
text, but I need each record to be separated by at least one carriage
return, and right now the text runs together. I've tried using chr(10),
several constants (I don't remember exactly what they are, something
like abNewLine or abCrLf) but they are all ignored.

I can type in the texbox and enter carriage returns, but not when I'm
loading data from the database. I'm sure there's a simple answer, but I
can't find it! Thanks for the help.

Paul

Ken Snell
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Text box question


ACCESS uses the combination of carriage return and line feed for a new line
(Chr(13) & Chr(10). This differs from some other MS Office software.

do until rstTable.EOF
txtBox.text = txtBox.text & rstTable!Description & chr(13) & Chr(10)
rstTable.MoveNext
Loop


--

Ken Snell
<MS ACCESS MVP>

"Access User" <notmyrealemail@somewhere.com> wrote in message
news:420ac8d9$0$29528$a1866201@visi.com...[color=blue]
> This seems like it should be easy, but I can't find the answer anywhere. I
> need to combine text fields from several different records into one text
> box for display purposes. Here's the code I'm using: (rstTable is a
> recordset)
>
> do until rstTable.EOF
> txtBox.text = txtBox.text & rstTable!Description & chr(13)
> rstTable.MoveNext
> Loop
>
> The problem is the text box ignores the carriage returns. I get all the
> text, but I need each record to be separated by at least one carriage
> return, and right now the text runs together. I've tried using chr(10),
> several constants (I don't remember exactly what they are, something like
> abNewLine or abCrLf) but they are all ignored.
>
> I can type in the texbox and enter carriage returns, but not when I'm
> loading data from the database. I'm sure there's a simple answer, but I
> can't find it! Thanks for the help.
>
> Paul[/color]


Paul Pentz
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Text box question


I thought I tried that, but I tried so many things I can't be sure.
I'll give it a try in the morning. Thanks.

Ken Snell wrote:[color=blue]
> ACCESS uses the combination of carriage return and line feed for a new line
> (Chr(13) & Chr(10). This differs from some other MS Office software.
>
> do until rstTable.EOF
> txtBox.text = txtBox.text & rstTable!Description & chr(13) & Chr(10)
> rstTable.MoveNext
> Loop
>
>[/color]
Mal Reeve
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Text box question


You can also use vbNewLine..
txtBox.text = txtBox.text & rstTable!Description + vbNewLine
(I use the + rather than & so that if it is a null entry (no description) I
don't get two empty lines)

HTH



"Paul Pentz" <ppentz@visi.com> wrote in message
news:420ae43a$0$21659$a1866201@visi.com...[color=blue]
>I thought I tried that, but I tried so many things I can't be sure. I'll
>give it a try in the morning. Thanks.
>
> Ken Snell wrote:[color=green]
>> ACCESS uses the combination of carriage return and line feed for a new
>> line (Chr(13) & Chr(10). This differs from some other MS Office software.
>>
>> do until rstTable.EOF
>> txtBox.text = txtBox.text & rstTable!Description & chr(13) & Chr(10)
>> rstTable.MoveNext
>> Loop
>>[/color][/color]

Access User
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Text box question


I didn't try using +, but I know I tried vbNewLine, and it didn't work.
I ended up using a variable first, then copying the variable to the
text box. I'm new enough to Access that it doesn't make any sense to
me, but it worked. Here's what I did:

txtVariable = txtVariable & rstTable!Description & chr(13) & chr(10)

then when the loop finished...

txtBox.text = txtVariable

If someone can explain to me why that made a difference, I'd sure like
to know!

Paul


Mal Reeve wrote:[color=blue]
> You can also use vbNewLine..
> txtBox.text = txtBox.text & rstTable!Description + vbNewLine
> (I use the + rather than & so that if it is a null entry (no description) I
> don't get two empty lines)
>
> HTH
>
>
>
> "Paul Pentz" <ppentz@visi.com> wrote in message
> news:420ae43a$0$21659$a1866201@visi.com...
>[color=green]
>>I thought I tried that, but I tried so many things I can't be sure. I'll
>>give it a try in the morning. Thanks.
>>
>>Ken Snell wrote:
>>[color=darkred]
>>>ACCESS uses the combination of carriage return and line feed for a new
>>>line (Chr(13) & Chr(10). This differs from some other MS Office software.
>>>
>>>do until rstTable.EOF
>>> txtBox.text = txtBox.text & rstTable!Description & chr(13) & Chr(10)
>>> rstTable.MoveNext
>>>Loop
>>>[/color][/color]
>
>[/color]
Closed Thread


Similar Microsoft Access / VBA bytes