Pasting text at the end of a field

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

Hi there
I've got a (tabbed) form that is used to generate letters
to clients. On the second tabbed page is a text library
(subform) that will be used to store commonly used
paragraphs of text. I've added a button to the subform
called Copy/Paste which I'm hoping will copy the text
onto the clipboard and then append the text to the end of
the 'blurb' in a control on the main form called
txtBody. What I can't work out is how to get the data to
append to the end of the txtBody field. If I use the
PasteAppend facility (DoCmd.RunCommand...) I'm told it
isn't available and if I just use the Paste facility the
autotext overwrites the text that's already in the
txtBody field.
Is there a way to get the cursor (focus) to jump to the
end of the field so that Paste works or is there a way to
get PasteAppend to work?
I hope you can help....I'm counting on you guys (as
usual!)
Kind Regards,

Lee
 
Is there a way to get the cursor (focus) to jump to the
end of the field so that Paste works or is there a way to
get PasteAppend to work?

Yep... set the textbox's SelStart property to the current length of
the field plus one:

Me.txtfield.SelStart = Len(Me!txtfield) + 1
 
Many thanks for the quick reply John.
There is just one issue and that is that the +1 bit
doesn't work. The pasted text adjoins the current text
without any spaces even if I put +2 after it.
I've also tried getting it to include a 'vbCrLf' in the
code but that's ignored too - it would be really nice if
the text could start on a new line but I'm not worried if
this isn't possible.
Best Regards

Lee
 
Many thanks for the quick reply John.
There is just one issue and that is that the +1 bit
doesn't work. The pasted text adjoins the current text
without any spaces even if I put +2 after it.

Well, of course. A blank IS A CHARACTER, just like any other
character. If you don't insert a " " or a Chr(32), you won't get a
blank inserted in the field.
I've also tried getting it to include a 'vbCrLf' in the
code but that's ignored too - it would be really nice if
the text could start on a new line but I'm not worried if
this isn't possible.

How did you try to insert the vbCrLf? It should work; please post your
code.
 
This is my current code to add a couple of spaces in
front of the autotext - the spaces are then removed from
the text library by using Trim. A bit clumsy eh?!

If IsNull([Text]) Then
MsgBox "There's nothing to copy!",
vbExclamation, "Text missing"
Else
Me.Text = " " & Me.Text
Call ClipBoard_SetData(Me.Text)
DoCmd.SelectObject acForm, "frm_GenerateLetter", False
DoCmd.GoToControl "txtBody"
Forms!frm_GenerateLetter!txtBody.SelStart = Len(Forms!
frm_GenerateLetter!txtBody)
DoCmd.RunCommand acCmdPaste
Me.Text = Trim(Me.Text)

End If
 
I've got a (tabbed) form that is used to generate letters
to clients. On the second tabbed page is a text library
(subform) that will be used to store commonly used
paragraphs of text. I've added a button to the subform
called Copy/Paste which I'm hoping will copy the text
onto the clipboard and then append the text to the end of
the 'blurb' in a control on the main form called
txtBody.

Try this code instead. The Clipboard is an unnecessary extraneous
complication!

Parent!txtBody = Parent!txtBody & vbCrLf & Me![Text]
 
That's better!!
I seem to have a knack of making things more complicated
than they really are!
Your help is much appreciated. Thanks once again.
Best wishes
Lee
-----Original Message-----
I've got a (tabbed) form that is used to generate letters
to clients. On the second tabbed page is a text library
(subform) that will be used to store commonly used
paragraphs of text. I've added a button to the subform
called Copy/Paste which I'm hoping will copy the text
onto the clipboard and then append the text to the end of
the 'blurb' in a control on the main form called
txtBody.

Try this code instead. The Clipboard is an unnecessary extraneous
complication!

Parent!txtBody = Parent!txtBody & vbCrLf & Me![Text]



.
 
Back
Top