How can I insert text in a textbox automatically?

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

Lee

Hi everyone
I've got a form that is used to generate Letters that
relate to a particular order. Once the user has selected
who the letter is to and how many copies to print etc...
they then go on to type the text of the letter in a
textbox. What I'd like to be able to do is add a command
button that will insert the signature details
automatically at the end of the letter. For example:

Yours Sincerely



John Smith
Company Name
Company Office

The command needs to locate the end of the text within
the textbox, insert a couple of carriage return/line
feeds and then insert the signature details. How can I
achieve this?
Any ideas would be very welcome.
Thanks!
Lee
 
hi

You should first set the property 'Enter Key Behavior' of text box to 'New Line in Field'
Then use the following code to add the text at the end of a text box. 'vbNewLine' is VBA constants that adds new line

Private Sub Command0_Click(
Text1 = Text1 & vbNewLine & vbNewLine & "your text
End Su

Shobha
 
What I did in a similar situation (with much help from
this group) is to make an unbound form (frmSendLetter)
containing an unbound combo box (cboSelectName) from which
I select the author's name. The row source for
cboSelectName is a query (qrySelectName) based on the
employee table. The field for the first column of
qrySelectName could be Name: [First] & " " & [Last]. The
second column in qrySelectName is [Title], and the third
is [Office]. This assumes that the words in brackets are
actual field names in your query. The row source
cboSelectName is one column from qrySelect name. Create
text boxes txtTitle and txtOffice. Make the control
source for txtTitle =[cboSelectName].[Column](1). The
first column is 0, so the second one is 1. Proceed
similarly for txtOffice. If there is to be custom text
for the letter, create a text box txtLetter. Set the
Enter key behavior to New Line. Add additional fields for
the recipient, etc. as needed. Finally, place a command
button on the form, with its On Click event set to
Me.Visible=False
Now create a report (rptLetter). Place a text box
(txtLetter) on the report. Set its control source to
=Forms!frmSelectName!txtLetter. Click the three dots next
to Control Source to use the Expression Builder as an
alternative to typing the reference. Remember the =
sign. Repeat for the other text boxes and combo boxes
from frmSendLetter.
In the On Open event for rptLetter, place the code:
DoCmd.OpenForm "frmSendLetter", , , , , acDialog
In the On Close event, place the code:
DoCmd.Close acForm, "frmSendLetter".
Save and close the form and the report. When you open the
report, it will show you the form. When you have
completed the form, the command button will hide the form
and allow the report to show. The form is still open, so
the text boxes on the report can reference controls on the
form. When you close the report, you also close the form.
It is probably possible to place a command on a custom
toolbar on the report to make the form visible again so
that the letter can be edited, but I have not gotten that
far.
There are other approaches to this same problem, but this
one has worked well for me.
 
Thank you for such a quick reply Shobha, that's great!!!
Kind regards,

Lee
-----Original Message-----
hi,

You should first set the property 'Enter Key Behavior'
of text box to 'New Line in Field'.
Then use the following code to add the text at the end
of a text box. 'vbNewLine' is VBA constants that adds new
line.
 
Thanks for such a comprehensive reply Bruce!
I have infact done the rest of the form/report where
users select the various fields that are 'dropped' into
the Letter automatically - it was just the business of
adding the signature that I'd got a mental block on.
I will, however, keep a copy of your reply for future as
I'm always pleased to steal other people's ideas!!
Kind regards,

Lee
-----Original Message-----
What I did in a similar situation (with much help from
this group) is to make an unbound form (frmSendLetter)
containing an unbound combo box (cboSelectName) from which
I select the author's name. The row source for
cboSelectName is a query (qrySelectName) based on the
employee table. The field for the first column of
qrySelectName could be Name: [First] & " " & [Last]. The
second column in qrySelectName is [Title], and the third
is [Office]. This assumes that the words in brackets are
actual field names in your query. The row source
cboSelectName is one column from qrySelect name. Create
text boxes txtTitle and txtOffice. Make the control
source for txtTitle =[cboSelectName].[Column](1). The
first column is 0, so the second one is 1. Proceed
similarly for txtOffice. If there is to be custom text
for the letter, create a text box txtLetter. Set the
Enter key behavior to New Line. Add additional fields for
the recipient, etc. as needed. Finally, place a command
button on the form, with its On Click event set to
Me.Visible=False
Now create a report (rptLetter). Place a text box
(txtLetter) on the report. Set its control source to
=Forms!frmSelectName!txtLetter. Click the three dots next
to Control Source to use the Expression Builder as an
alternative to typing the reference. Remember the =
sign. Repeat for the other text boxes and combo boxes
from frmSendLetter.
In the On Open event for rptLetter, place the code:
DoCmd.OpenForm "frmSendLetter", , , , , acDialog
In the On Close event, place the code:
DoCmd.Close acForm, "frmSendLetter".
Save and close the form and the report. When you open the
report, it will show you the form. When you have
completed the form, the command button will hide the form
and allow the report to show. The form is still open, so
the text boxes on the report can reference controls on the
form. When you close the report, you also close the form.
It is probably possible to place a command on a custom
toolbar on the report to make the form visible again so
that the letter can be edited, but I have not gotten that
far.
There are other approaches to this same problem, but this
one has worked well for me.
-----Original Message-----
Hi everyone
I've got a form that is used to generate Letters that
relate to a particular order. Once the user has selected
who the letter is to and how many copies to print etc...
they then go on to type the text of the letter in a
textbox. What I'd like to be able to do is add a command
button that will insert the signature details
automatically at the end of the letter. For example:

Yours Sincerely



John Smith
Company Name
Company Office

The command needs to locate the end of the text within
the textbox, insert a couple of carriage return/line
feeds and then insert the signature details. How can I
achieve this?
Any ideas would be very welcome.
Thanks!
Lee
.
.
 
Back
Top