Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cursor postion within a textbox

Status
Not open for further replies.

Kavius

Programmer
Apr 11, 2002
322
CA
I have a textbox on a form in which I need to know the cursor position on a keypressed event. I did check the textbox.SelStart value but it always contains 0. Any other ideas? ---------------------------------------
Where would one begin to study Myology?
 
I have tryed SelText, SelLength etc. etc. they all return 0 or blank I do not think access can give you the location of the cursor.
However you can drop the user at the end of a text in a field by useing the F2 key.
Normally I say that access can do anything but make coffee but it looks like I have to add "and give me the position of the cursor".
Every tuesday I meet with some other guys and I shall bring this thing up and return with any news that I can get.

Herman
 
I did a quick test using Access 97.

In the textbox_KeyPress event, textbox.selStart gives the position of the cursor in the textfield (starting with 0)

Niki --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
I am using Access 2000, and the client is using XP.

On a side note I'm still working on a way to get Access to win the lottery for me. That's not working so well either.
---------------------------------------
Where would one begin to study Myology?
 
Text1.SelStart works on Access 2000 just fine. There are certain keys that don't fire the keypress event, such as the arrow keys.

Try using the KeyUp event which captures all the keys. Put the following code in the 2 events and you can watch the results in the status bar:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
  SysCmd acSysCmdSetStatus, Text1.SelStart & " - KeyPress"
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
  SysCmd acSysCmdSetStatus, Text1.SelStart & " - KeyUP"
End Sub

Remember that position 0 is the first position, as already stated. VBSlammer
redinvader3walking.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top