setting cursor in memo field, how?

G

Guest

I have a tab control with several tabs containing memo fields. these fields
can be locked or unlocked. When I switch tabs, if a memo field is locked I
want to put the cursor at the top and if unlocked at the end. I tried the
following but it failed to work:
ctl.setfocus
if ctl.locked = true then
sendkeys "^{HOME}"
else
sendkeys "^{END}"
end if
 
J

John W. Vinson

I have a tab control with several tabs containing memo fields. these fields
can be locked or unlocked. When I switch tabs, if a memo field is locked I
want to put the cursor at the top and if unlocked at the end. I tried the
following but it failed to work:
ctl.setfocus
if ctl.locked = true then
sendkeys "^{HOME}"
else
sendkeys "^{END}"
end if

Use the SelStart property instead: Sendkeys is buggy, unreliable, and may not
even be supported in 2007 (based on another thread here, not personal
experience).

Try

If ctl.Locked Then
ctl.SelStart = 0
Else
ctl.SelStart = Len(ctl & "")
End If

John W. Vinson [MVP]
 
M

missinglinq via AccessMonster.com

I have a feeling that few people actually use anywhere near the 65k limit
that a memo field allows, but just be aware that SelStart accepts an Integer,
and so the code will cause an "Error 6 Overflow" and bomb if the length of
the field is greater than 32767 characters.

If there's a chance of this happening, yuo need to modify John's code to
something like:

If ctl.Locked Then
ctl.SelStart = 0
Else
If Len(ctl) < 32767 Then
ctl.SelStart = Len(ctl & "")
else
ctl.SelStart = 32767
End If

which will move the cursor halfway or better towards the end of the field.

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

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
J

John W. Vinson

I have a feeling that few people actually use anywhere near the 65k limit
that a memo field allows, but just be aware that SelStart accepts an Integer,
and so the code will cause an "Error 6 Overflow" and bomb if the length of
the field is greater than 32767 characters.

VERRY interesting.... thanks, Linq, I didn't realize that!

John W. Vinson [MVP]
 
G

Guest

The 'selstart' methos causes errors when the memo field length exceeds the
max value of an integer. That's exactly why I'm using 'sendkeys'.
 

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