How to insert a New Line into a text field?

R

Ryan Langton

How do I insert a new line into an nvarchar field?

If I'm using Access, I can set the Enter key behavior for a text field to go
to a new line. When I look at the table data, it appears as new lines. If
I'm not using an Access form however to input the data (I want my VB code to
insert a new line and some text to the field), how do I do that?

Thanks,
Ryan
 
D

Douglas J. Steele

Me.MyControl = "This is the first line." & vbCrLf & "This is the second
line."
 
R

Ryan Langton

Sorry I wasn't clear. This would work if I have a control for said field on
the form. I do not have a control (for this particular field) on the form.
When the user performs a certain action, I want to insert (directly into an
nvarchar field in my SQL database) a newline followed by text. So for
example I would think I could do this with an UPDATE statement... 'UPDATE
table SET fieldA = fieldA + \n + "my added text"'... or something like that?

Thanks,
Ryan
 
D

Douglas J. Steele

Try SET fieldA = fieldA + Char(13) + Char(10) + "my added text"'

(Char(13) is Carriage Return, Char(10) is Line Feed)
 

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