Inserting text into a memo field (1 Viewer)

Kiwi-Wombat

Registered User.
Local time
Yesterday, 20:42
Joined
Aug 2, 2004
Messages
56
Forgive me if this question has already been asked and solved. Just point me to the thread.

Basically what I want to do is add a specific piece of text to a text field / memo field (at the point where the cursor is) on the click of a button. I then want the cursor to be active at that point so I can continue typing without having to click back into the text field. The text could be hard coded or even double-click action from a separate lookup field

I tried Me.NameOfField = Me.NameOfField & "text to be added".

(I think that is the code. I am away from my home computer at the momemt so can't look it up)

This works perfectly except that it adds the text to the end of the existing text. If your cursor is on the next line or has gone down a couple of lines to start a new paragraph, the inserted text removes these because essentially the are NULL in terms of text. Also the focus has been lost so you have to click on the text / memo field again before you can type

I know this works because I have seen it, but it was a commercial programme and I could view the code.

Note these are shortcuts for commonly added pieces of text and I need several of these buttons to add different things.

I have also tried autokeys which works but the user has to remember which CNTL combination does what.

I presume Send Keys does it somehow but I can't get that to work

Any help would be appreciated
 

WayneRyan

AWF VIP
Local time
Today, 04:42
Joined
Nov 19, 2002
Messages
7,122
hi kiwi,

This will add it at the beginning, with a carriage-Return and
line-feed between them.

Me.NameOfField = "text to be added" & vbCrLf & Me.NameOfField

Look at the properties for text boxes:

.SelStart
.SelLength

They will let you position the cursor in a field and, if wanted,
select (or highlight) a segment of it.

Wayne
 

Kiwi-Wombat

Registered User.
Local time
Yesterday, 20:42
Joined
Aug 2, 2004
Messages
56
Thanks that seems to work

If I do the following code

Me.TextField = Me.TextField & vbCrLf & "text to be added "
Me.TextField.SetFocus
Me.TextField.SelStart = 10000

it adds the text at the end of the existing text but on a new line. Because the memo field will never be that long, by using .selstart = 10000 ensures that the cursor defaults to the end of the text.

Thanks for your help
 

Users who are viewing this thread

Top Bottom