Simulate "New line in field" in code????

P

Paul Baxter

If I set a text box's "Enter Key Behavior" to "New Line in
Field", hitting the Enter key inserts Chr(10) Chr(13) in
the underlying table to separate the data of the two lines.

But, if I try to duplicate this by running an update query
(or do the same in code in the form's Current event) that
combines two fields' data:
[Field3] = [Field1] & Chr(10) & Chr(13) & [Field2]
when the form looks at that field the textbox lines are
not separated but instead look like:
Field1||Field2

How can I combine 2 or more fields into separate lines in
a third field?

TIA,

Paul
 
A

Allen Browne

The Carriage Return needs to be before the line feed:
[Field3] = [Field1] & Chr(13) & Chr(10) & [Field2]

Easier still:
[Field3] = [Field1] & vbCrLf & [Field2]

BTW, hopefull Field3 is an unbound control in this example? You don't want
to be dirtying the record in the form's Current event.

If it is unbound, and the user does not need to type over it, you could just
set the ControlSource of the text box to:
= [Field1] & Chr(13) & Chr(10) & [Field2]
 
P

Paul Baxter

Thanks, Allen. I'll try that.

-----Original Message-----
The Carriage Return needs to be before the line feed:
[Field3] = [Field1] & Chr(13) & Chr(10) & [Field2]

Easier still:
[Field3] = [Field1] & vbCrLf & [Field2]

BTW, hopefull Field3 is an unbound control in this example? You don't want
to be dirtying the record in the form's Current event.

If it is unbound, and the user does not need to type over it, you could just
set the ControlSource of the text box to:
= [Field1] & Chr(13) & Chr(10) & [Field2]

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

If I set a text box's "Enter Key Behavior" to "New Line in
Field", hitting the Enter key inserts Chr(10) Chr(13) in
the underlying table to separate the data of the two lines.

But, if I try to duplicate this by running an update query
(or do the same in code in the form's Current event) that
combines two fields' data:
[Field3] = [Field1] & Chr(10) & Chr(13) & [Field2]
when the form looks at that field the textbox lines are
not separated but instead look like:
Field1||Field2

How can I combine 2 or more fields into separate lines in
a third field?

TIA,

Paul


.
 

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