Set the insertion point in a text field

G

Guest

I have a memo field that I store Date/Time Stamped comments in. I have
locked the field and provided a button. The button opens a dialog window
where the user can enter the comment. I then place a Date/Time Stamp in the
beginning of the locked field, followed by the contents of the dialog window,
then by 2 linefeeds and then the original contents of the field. In this
way, the most recent comment is at the top.

HOWEVER, I would rather unlock the field, insert the 2 line feeds, then put
the new Date/Time Stamp in front of that, and leave the field unlocked with
the curser blinking a couple of spaces past the Date/Time Stamp. When they
leave the field, it would re-lock.

How do I set the cursor at a selected point in a field?
 
M

Marshall Barton

Bill said:
I have a memo field that I store Date/Time Stamped comments in. I have
locked the field and provided a button. The button opens a dialog window
where the user can enter the comment. I then place a Date/Time Stamp in the
beginning of the locked field, followed by the contents of the dialog window,
then by 2 linefeeds and then the original contents of the field. In this
way, the most recent comment is at the top.

HOWEVER, I would rather unlock the field, insert the 2 line feeds, then put
the new Date/Time Stamp in front of that, and leave the field unlocked with
the curser blinking a couple of spaces past the Date/Time Stamp. When they
leave the field, it would re-lock.

How do I set the cursor at a selected point in a field?

Use the text box's SelStart and SelLength properties.

The button's Click event code might look something like
this:

Me.memo.SetFocus
Me.memo.Locked = False
strTimeStamp = Format(Now(), "d mmm yyyy, h:nn") & " "
Me.memo = strTimeStamp & vbCrLf & vbCrLf & Me.memo
Me.memo.SelStart = Len(strTimeStamp)
Me.memo.SelLength = 0

and the memo text box's Exit event would relock itself.

Me.memo.Locked = True
 

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