Insert text string

  • Thread starter Thread starter ed
  • Start date Start date
E

ed

I would like to insert a string of text into a comment form field. The text
in this field is multiple lines and I would like to insert a specific string
of text at the end of certain lines of text within the comment field. In
other words I would insert the text where I place my cursor. Any solutions.

Thanks
 
You need a comments field in your table that is set to datatype text. Tie the
comment form field to the table comments field. Now whatever comments you
type on the form will be saved in the table. Remember that it can only be 255
letters long.
 
Sorry for not being more specific. I already have the comment field and it
contains multilines of text. My goal is to insert text at the location of my
cursor, see example below.

Form Comment Field

Line of existing text
Second line of existing text - Need to enter a string of text here after the
existing text
Third line of existing text

I would define the string of text to enter.

Thanks for your help.
 
Hi Ed,
To resolve this issue, you need to capture the focus position. I write the
following code for you, please check if it works at your side:
Private Sub Command7_Click()
Me.Comments.Value = Left$(Me.Comments.Value, startPos) & "_TEST_" &
Right$(Me.Comments.Value, Len(Me.Comments.Value) - startPos)
End Sub

Private Sub Comments_GotFocus()
startPos = Me.Comments.SelStart
End Sub

Private Sub Comments_LostFocus()
startPos = Me.Comments.SelStart
End Sub

However the above code has a minor issue. When you input something to the
comment field and then move the focus to a middle position without leaving
the focus from the comment field, the text "_TEST_" cannot be correctly
inserted. I am trying to perform further research on this issue and will
reply back as soon as possible.

Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
Thanks Charles, the code does place the "_TEST_" text into my comment field
at the very left top start of my existing text but not at the cursor
location. I will wait for the results of your research. Much appreciated.
 
Hi Ed,
I figure it out. It is easier to use the On Click event of the comment text
box, please refer to the following code:
==========================================
Private startPos As Integer

Private Sub Command7_Click()
Me.Comments.Value = Left$(Me.Comments.Value, startPos) & "_TEST_" &
Right$(Me.Comments.Value, Len(Me.Comments.Value) - startPos)
End Sub

Private Sub Comments_Click()
startPos = Me.Comments.SelStart
End Sub
===========================================

Hope this helps. Please feel free to let me know if you have any other
questions or concerns. Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
Thanks Charles,

I have tried the code and I have one problem. When I break and check
Private Sub Comments_Click()
startPos = Me.Comments.SelStart
The value of Me.Comments.SelStart is correct but when I break and check the
value of startPos at:
Me.Comments.Value = Left$(Me.Comments.Value, startPos) & "_TEST_" &
Right$(Me.Comments.Value, Len(Me.Comments.Value) - startPos)
it is Empty.

It does not seem to pass the value of startPos on from the first code to the
second code. Thus the "_TEST_" is always insterted at the begining of the
comment field.

Ed

Ed
 
Hi Ed,
Where did you declare the variable startPos? It should be declared outside
your function/sub and in (General) scope.

I have tested the code in both Access 2003 and 2007, it worked fine. Anyway
if you would like, you could leave me (changliw_at_microsoft_dot_com) an
email response and I will send my sample to you.


Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
Hi Ed,
Thank you for your feedback.

I am very glad to see it works. If you have any other questions or
concerns, please feel free to let me know. It is my pleasure to be of
assistance.

Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
Back
Top