Scroll at the end of memo field in form view

J

Jatin

I have memo field displayed in form with scroll bar on memo field. When I
open form, I would like to see the text scrolled to bottom of the box instead
of top
 
L

Linq Adams via AccessMonster.com

Placing this code in the form current event will pop a “2185 You can't
reference a property or method for a control unless the control has the
focus†error, even if the control holding the memo field is the first to get
focus, so it needs to be in the GotFocus event.

Private Sub MyMemoControl_GotFocus()
Me.MyMemoControl.SelStart = Len(Me.MyMemoControl)
End Sub

This code will work with the vast majority of memo fields, I suspect, but
will also cause an error if you have a memo field, which can hold 64 K
characters, with more than 32,767 characters. This is because SelStart takes
an Integer as an argument, which is limited to 32,767. So if there’s any
chance that your memo fields will exceed this limit, you should test it's
length and if it's greater than 32767 set it to 32767, which would at least
get you a whole lot closer to the end of the data.

Private Sub MyMemoControl_GotFocus()
If Len(MyMemoControl) > 32767 Then
MyMemoControl.SelStart = 32767
Else
MyMemoControl.SelStart = Len(MyMemoControl)
End If
End Sub

I seem to remember Leban posting a link to a hack that used an API call to
actually move it to the end of the text, regardless of length, but can’t find
the link.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 

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