Add new line in memo

J

Jone

Hi,
What code do I write when I want to set the focus in a field that’s a memo
and I should automatically go to the last line and enter (because I have
already have data in that memo)
 
D

Daniel Pineault

For instance if your memo control's (not field, a field is in a table) name
is memo then the following would work

Me.memo = Me.memo & vbCrLf & "new text"
 
S

Stuart McCall

Jone said:
Hi,
What code do I write when I want to set the focus in a field that’s a memo
and I should automatically go to the last line and enter (because I have
already have data in that memo)

With Me.MemoControlName
.SetFocus
.SelStart = Len(.Text) + 1
.SelLength = 0
End With
 
J

John W. Vinson

Hi,
What code do I write when I want to set the focus in a field that’s a memo
and I should automatically go to the last line and enter (because I have
already have data in that memo)

Well... the need to do this strongly suggests that you may be misusing the
memo field.

If you're trying to keep multiple more-or-less independent notes with
reference to a record, you may want to consider a one-to-many relationship to
a Notes table. This could have a datefield with a default value of Now() to
timestamp each note, and perhaps a text field to capture the user ID or name
of the person entering the note; you'ld use a Subform to enter the notes.

That said... in the memo field's textbox control on the form, you can edit the
control's Got Focus event to something like

Private Sub textboxname_GotFocus()
Me!textboxname = Me!textboxname & vbCrLf
Me!textboxname.SelStart = Len(Me!textboxname)
End Sub

to insert a newline (CR - LF pair) and put the insertion point at the end.

John W. Vinson [MVP]
 

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