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.