Set Cursor at end of memo in text box

J

Jael

Using MS Access 2003-Vista Ultimate-
I have a text box called txtJournal which has a memo field as it's control.
I use an option button to add a new entry. I use .SelLength & .SelStart to
position the cursor to the end and add a TDS whenever I add to the field.
This works fine until I get several lines. At this point, .SelLength shows
the correct value (~1123), but the .SetStart constantly places the cursor a
specific line rather than end. Is .SelLen limited in size?

Insight would be appreciated...
Jael

BTW is there any "gotchas" using memo that I should be careful of
encountering?

Code is:
Private Sub optJournalDate_Click()
If Me.optJournalDate Then
If Right(txtJournal, 1) = ";" Then 'Last line terminated?
Me.txtJournal = Me.txtJournal & vbCrLf & Format(Date,
"mm/dd/yy") & ": "
Else 'if not, terminate it properly
Me.txtJournal = Me.txtJournal & ";" & vbCrLf & Format(Date,
"mm/dd/yy") & ": "
End If
Me.txtJournal.SetFocus 'Make sure the focus is set
Me!txtJournal.SelStart = Me.txtJournal.SelLength
Me.optJournalDate = False 'reset option button
End If
End Sub
 
M

Marshall Barton

Jael said:
Using MS Access 2003-Vista Ultimate-
I have a text box called txtJournal which has a memo field as it's control.
I use an option button to add a new entry. I use .SelLength & .SelStart to
position the cursor to the end and add a TDS whenever I add to the field.
This works fine until I get several lines. At this point, .SelLength shows
the correct value (~1123), but the .SetStart constantly places the cursor a
specific line rather than end. Is .SelLen limited in size?

Insight would be appreciated...
Jael

BTW is there any "gotchas" using memo that I should be careful of
encountering?

Code is:
Private Sub optJournalDate_Click()
If Me.optJournalDate Then
If Right(txtJournal, 1) = ";" Then 'Last line terminated?
Me.txtJournal = Me.txtJournal & vbCrLf & Format(Date,
"mm/dd/yy") & ": "
Else 'if not, terminate it properly
Me.txtJournal = Me.txtJournal & ";" & vbCrLf & Format(Date,
"mm/dd/yy") & ": "
End If
Me.txtJournal.SetFocus 'Make sure the focus is set
Me!txtJournal.SelStart = Me.txtJournal.SelLength
Me.optJournalDate = False 'reset option button
End If
End Sub


If there's a limit, I would expect it to be 64K. OTOH, I
don't see how you can guarantee that SelLength has any
specific value. When a text box receives the focus, there
may not be any selected text (SelLength =0) depending on
property settings (e,g, Behavior Entering Field)

I think you should explicitly set both SelStart and
SelLength:
Me.SelStart = Len(Me!txtJournal)
Me.SelLength = 0
 
J

Jael

Thanks for the response. I use memo fields for journal entries (Diaries)
relating to properties I manage. It's strictly a narrative and I don't
search it or qualify it in any way.

While Marshalls resolved my problem, I also tried to follow the URL in your
response - no page. Went to Allen's WEB page but have not be able to locate
your reference. Was the URL accurate?

Thanks again for your quick response.
Jael California Desert Dweller - it's a dry heat!
 
J

Jael

Linq,
Took me awhile to get back here - Thanks for the update, works better that
way. I have a bag of spare dashes - should have figured that one out myself.

Thanks,
Jael
 

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