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
 
L

Linq Adams via AccessMonster.com

I've used memo fields without trouble for a number of years now, by adhering
to one simple rule; use memo fields only for golding memos, i.e. notes. Do
not use it to store data that you will ever need to search, sort or
manipulate in any way!

Crosstab queries, Summary queries, Union queries, and Queries that use
Distinct or DistinctRow will all truncate a memo field to 255 characters so
Access can perform the required functionality of eliminating duplicates.

Also, if you have specified a format in the field's Format property, this
will often truncate the data as well. If Unique Value Property is set to Yes,
Access has to compare the values and therefore Memo Field values are
truncated.

Here's a great site from Allen Browne for more extensive explanation and work
arounds

http://allenbrowne.com/ser 63.html

SelLength and SelStart both take an Integer as an argument (which is limited
to 32,767) but a Memo field can hold twice that many characters (actually
almost four times that, I understand, if the data is entered via code) so you
have to be careful using them with these fields! I can't imagine selecting an
entire memo field, but if you wanted to, say, place the cursor at the end of
the field, you should test it's length and if Len(YourMemoField) > 32767 set
it to 32767, which would at least get you a whole lot closer to the end of
the data.

If Len(YourMemoField) > 32767 Then
YourMemoField.SelStart = 32767
Else
YourMemoField.SelStart = Len(YourMemoField)
End If
 
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