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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert text at a cursor position in a field

Status
Not open for further replies.

jojones

Programmer
Dec 4, 2000
104
AU
I need to insert some text into a field at the cursor position which will not always be at the start or end of the text.... Can someone help me with this please... either to identify the cursor/character position to insert the text, or something... help.... pleeeaaassseee

Jo :)
 
Hey Jo,
Is there going to be a certain character that will signal were the inserted text is supposed to go. Like
Code:
insert 'abc' everytime you see a ':'?[/code/
Let me know...I have had simular situations. Maybe I can Help ::-)
 
Hey Jo,
Is there going to be a certain character that will signal were the inserted text is supposed to go. Like
Code:
insert 'abc' everytime you see a ':'?[/code/
Let me know...I have had simular situations. Maybe I can Help 
Scoty ::-)
 
Hey Scoty.... unfortunately not. It's just inserting a time/date stamp in text whereever the cursor is when the button is pushed. There will be no set text at the insertion point... and the inserted text is just now()...

can you help??
Jo
:eek:)
 
You could use some variation of the following in the Click event procedure for your button:
Code:
    Screen.PreviousControl.SetFocus
    SendKeys CStr(Now())
SendKeys has the same effect as typing the characters on the keyboard--including the fact that, if the wrong window has the focus, the result could be disastrous. So make sure you SetFocus back to the control that contains the text insertion cursor, before you issue SendKeys.

BTW, how do you know there IS an insertion cursor? If the user selects the entire contents of the control, there is a selection but no cursor. If the user then clicks your button, this simple SendKeys technique will replace the whole thing (just like keyboard typing would do).

Note: SendKeys is fine for a quick-and-dirty solution, but it's not a great solution in general because of dangers like the above. If you need hardier code, you'll have to do more work. But if this is just for your personal use, it may be good enough.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top