Cursor position in text box 
Author Message
 Cursor position in text box

Hello,
is it available to get current cursor position in Access 97 text field?
.SelStart works only if i select at least one character in text box,
otherwise it returns 0.
I need this to build something like Access expression builder.

--
Best regards,
___________
Alex Dybenko
Point Limited

Home Page: http://www.*-*-*.com/
Moscow MS Access User Group, chairman
http://www.*-*-*.com/



Fri, 14 Jul 2000 03:00:00 GMT  
 Cursor position in text box

Hi Alex,

SelStart works even if no text is selected. To prove this, try
inserting the following code behind a textbox, and click into existing
text:

Private Sub Text2_Click()
    MsgBox "SelStart: " & Me!Text2.SelStart
End Sub

If, for example the textbox contains "abcd" and you click between the
b and c, the message will read, "SelStart: 2".

So there must be something else going on if you are getting only zero
values.

 -- Andy

Quote:

>Hello,
>is it available to get current cursor position in Access 97 text field?
>.SelStart works only if i select at least one character in text box,
>otherwise it returns 0.
>I need this to build something like Access expression builder.

>--
>Best regards,
>___________
>Alex Dybenko
>Point Limited

>Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
>Moscow MS Access User Group, chairman
>http://www.arimsoft.ru/msaccess



Fri, 14 Jul 2000 03:00:00 GMT  
 Cursor position in text box

Andy/Alex

You get a value of Zero for SelStart when no text is selected and the
cursor is in front of the first character OR the highlighted text starts
with the first character.

Hope this helps

Terry



Quote:
> Hi Alex,

> SelStart works even if no text is selected. To prove this, try
> inserting the following code behind a textbox, and click into existing
> text:

> Private Sub Text2_Click()
>     MsgBox "SelStart: " & Me!Text2.SelStart
> End Sub

> If, for example the textbox contains "abcd" and you click between the
> b and c, the message will read, "SelStart: 2".

> So there must be something else going on if you are getting only zero
> values.

>  -- Andy


> >Hello,
> >is it available to get current cursor position in Access 97 text field?
> >.SelStart works only if i select at least one character in text box,
> >otherwise it returns 0.
> >I need this to build something like Access expression builder.

> >--
> >Best regards,
> >___________
> >Alex Dybenko
> >Point Limited

> >Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
> >Moscow MS Access User Group, chairman
> >http://www.arimsoft.ru/msaccess



Fri, 14 Jul 2000 03:00:00 GMT  
 Cursor position in text box

Hi Andy,
thank you, it really works
but how to determine SelStart, when you loose focus from this field?
I tried both onExit and OnLostFocus, SelStart returns only 0
for example i have a text box and button on same form, i set cursor
somewhere in the text box, and then, when i press button i need to insert
there any text
To catch all text box events (on change, on click, etc.) and then use the
last SelStart?
Maybe there is an easy way?
Best regards,
___________
Alex Dybenko
Point Limited

Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
Moscow MS Access User Group, chairman
http://www.arimsoft.ru/msaccess

Quote:

>Hi Alex,

>SelStart works even if no text is selected. To prove this, try
>inserting the following code behind a textbox, and click into existing
>text:

>Private Sub Text2_Click()
>    MsgBox "SelStart: " & Me!Text2.SelStart
>End Sub

>If, for example the textbox contains "abcd" and you click between the
>b and c, the message will read, "SelStart: 2".

>So there must be something else going on if you are getting only zero
>values.

> -- Andy


>>Hello,
>>is it available to get current cursor position in Access 97 text field?
>>.SelStart works only if i select at least one character in text box,
>>otherwise it returns 0.
>>I need this to build something like Access expression builder.

>>--
>>Best regards,
>>___________
>>Alex Dybenko
>>Point Limited

>>Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
>>Moscow MS Access User Group, chairman
>>http://www.arimsoft.ru/msaccess



Sat, 15 Jul 2000 03:00:00 GMT  
 Cursor position in text box

Here are the rules you will have to work with, Alex:

If the textbox is updated, then the BeforeUpdate and AfterUpdate
events will give you the correct selstart, but the Exit and LostFocus
events will give you zero.

If the textbox is not updated, then the BeforeUpdate and AfterUpdate
events will not fire and the Exit and LostFocus events will give you
the correct selstart.

Hope that helps. It is an interesting problem.

 -- Andy

Quote:

>Hi Andy,
>thank you, it really works
>but how to determine SelStart, when you loose focus from this field?
>I tried both onExit and OnLostFocus, SelStart returns only 0
>for example i have a text box and button on same form, i set cursor
>somewhere in the text box, and then, when i press button i need to insert
>there any text
>To catch all text box events (on change, on click, etc.) and then use the
>last SelStart?
>Maybe there is an easy way?
>Best regards,
>___________
>Alex Dybenko
>Point Limited

>Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
>Moscow MS Access User Group, chairman
>http://www.arimsoft.ru/msaccess

>>Hi Alex,

>>SelStart works even if no text is selected. To prove this, try
>>inserting the following code behind a textbox, and click into existing
>>text:

>>Private Sub Text2_Click()
>>    MsgBox "SelStart: " & Me!Text2.SelStart
>>End Sub

>>If, for example the textbox contains "abcd" and you click between the
>>b and c, the message will read, "SelStart: 2".

>>So there must be something else going on if you are getting only zero
>>values.

>> -- Andy


>>>Hello,
>>>is it available to get current cursor position in Access 97 text field?
>>>.SelStart works only if i select at least one character in text box,
>>>otherwise it returns 0.
>>>I need this to build something like Access expression builder.

>>>--
>>>Best regards,
>>>___________
>>>Alex Dybenko
>>>Point Limited

>>>Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
>>>Moscow MS Access User Group, chairman
>>>http://www.arimsoft.ru/msaccess



Sat, 15 Jul 2000 03:00:00 GMT  
 Cursor position in text box

Andy,
thank you very much!
i forgot about these events
Now i have solved this

Alex

Quote:

>Here are the rules you will have to work with, Alex:

>If the textbox is updated, then the BeforeUpdate and AfterUpdate
>events will give you the correct selstart, but the Exit and LostFocus
>events will give you zero.

>If the textbox is not updated, then the BeforeUpdate and AfterUpdate
>events will not fire and the Exit and LostFocus events will give you
>the correct selstart.

>Hope that helps. It is an interesting problem.

> -- Andy



Sat, 15 Jul 2000 03:00:00 GMT  
 Cursor position in text box

Use a variable to hold the value of Selstart.


Quote:
>Hi Andy,
>thank you, it really works
>but how to determine SelStart, when you loose focus from this field?
>I tried both onExit and OnLostFocus, SelStart returns only 0
>for example i have a text box and button on same form, i set cursor
>somewhere in the text box, and then, when i press button i need to insert
>there any text
>To catch all text box events (on change, on click, etc.) and then use the
>last SelStart?
>Maybe there is an easy way?
>Best regards,
>___________
>Alex Dybenko
>Point Limited

>Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
>Moscow MS Access User Group, chairman
>http://www.arimsoft.ru/msaccess

>>Hi Alex,

>>SelStart works even if no text is selected. To prove this, try
>>inserting the following code behind a textbox, and click into existing
>>text:

>>Private Sub Text2_Click()
>>    MsgBox "SelStart: " & Me!Text2.SelStart
>>End Sub

>>If, for example the textbox contains "abcd" and you click between the
>>b and c, the message will read, "SelStart: 2".

>>So there must be something else going on if you are getting only zero
>>values.

>> -- Andy


>>>Hello,
>>>is it available to get current cursor position in Access 97 text field?
>>>.SelStart works only if i select at least one character in text box,
>>>otherwise it returns 0.
>>>I need this to build something like Access expression builder.

>>>--
>>>Best regards,
>>>___________
>>>Alex Dybenko
>>>Point Limited

>>>Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
>>>Moscow MS Access User Group, chairman
>>>http://www.arimsoft.ru/msaccess



Sat, 15 Jul 2000 03:00:00 GMT  
 Cursor position in text box

Thanks, Terry,
I use a variable to hold the value of Selstart  from afterupdate or exit
events, depending on last operation with this field.
So the problem is solved!

Another question:
Access automatically trims spaces (chr$(32)) at the end of the field. Is it
available to switch off this feature?
for example, if i type, without quotes, "Hello      ", the field will be
"Hello"

Alex

Quote:

>Use a variable to hold the value of Selstart.



Sun, 16 Jul 2000 03:00:00 GMT  
 Cursor position in text box

Hi Alex

I take it that what is happening is that you type into the text box, move
away to add something and then wen you move back the trailing space has been
trimmed, there's a couple of ways around that;

1) When ever you return to the box append a space to it.

2) Whenever you leave the box store it's text in a variable and then restore
the text when you return.

I wrote a similar system for a report wizard addin that I created, I seem to
remember that I used a combination of the two options depending upon the
.SelStart position relative to the length of the field. that is if the
.SelStart was equal to the length I used option 1, if it was not equal I
used option 2.

I also did some other tests such as was the last character a ( or a [, and
so on. It worked out reasonably well in the end.

Quote:

>Thanks, Terry,
>I use a variable to hold the value of Selstart  from afterupdate or exit
>events, depending on last operation with this field.
>So the problem is solved!

>Another question:
>Access automatically trims spaces (chr$(32)) at the end of the field. Is it
>available to switch off this feature?
>for example, if i type, without quotes, "Hello      ", the field will be
>"Hello"

>Alex


>>Use a variable to hold the value of Selstart.



Sun, 16 Jul 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Finding Cursor Position In Text Box

2. Maintaining cursor position in text box

3. Getting Cursor position in text box - how?

4. How to find cursor position in text box

5. Cursor Position in Text Boxes

6. Cursor position in text box

7. Cursor position in text box

8. Text box cursor position when text is selected

9. Positioning the Cursor in the first text box of a User Form

10. Help setting cursor position in a text box

11. Cursor Position in a Multiline Text Box

12. How to Set Cursor Position in a Text Box

 

 
Powered by phpBB® Forum Software