Inserting predefined text strings in a text box

G

Guest

I want to append text to a "Comments" memo field. The table only has two
fields: Order# and Comments (this table will be related to a linked table
from another database because I don't have authority to modify the other
table).

I thought I would have a simple form that has a text box for the record ID,
a text box to enter text and a text box to show the contents of the Comments
data element. The user will type in the record ID then type the text to be
appended then push a button and the current date & time and text will be
appended to the Comments.

There are a few standard phrases, so I wanted command buttons (eg. "Waiting
for QDR") to simplify data entry. I coded the On Click event:

Private Sub cmdWaitQDR_Click()
txtAdd.Text = "Waiting for QDR"
End Sub

When I click the button, I get a "Run-time error '2185': You can't
reference a property or method for a control unless the control has the
focus."

What have I done wrong? Would it be better to do this with a Combo Box that
is preloaded with common phrases?

I realize that I will need another command button to concatenate the date
and time to this textbox.text and then append to the [Comments] field before
adding the record to the table.

Thanks
 
J

JohnGriffiths

There are a few standard phrases, so I wanted command buttons (eg. "Waiting
for QDR") to simplify data entry. I coded the On Click event:

Private Sub cmdWaitQDR_Click()
txtAdd.Text = "Waiting for QDR"
End Sub

Private Sub cmdWaitQDR_Click()
txtAdd = "Waiting for QDR"
End Sub
When I click the button, I get a "Run-time error '2185': You can't
reference a property or method for a control unless the control has the
focus."

The ".Text" property is causing this behaviour.
What have I done wrong? Would it be better to do this with a Combo Box that
is preloaded with common phrases?

I realize that I will need another command button to concatenate the date
and time to this textbox.text and then append to the [Comments] field before
adding the record to the table.

Don't bother if you *need* to capture the date; add a date field, makes
sense - No?
A value of "=Now()" for the default value means no one has to enter it.

The value "Waiting for QDR" implies that you are tracking the status, add a
field to store the status.
On the UI use a combo to restrict to valid statuses and use the current
Comments field for relevant information.

If you have a status of "On Hold" you will need a field to store the status
that was interrupted to allow backtracking.

I could go on - John
 
J

John Vinson

Private Sub cmdWaitQDR_Click()
txtAdd.Text = "Waiting for QDR"
End Sub

When I click the button, I get a "Run-time error '2185': You can't
reference a property or method for a control unless the control has the
focus."

Use the textbox's Value property instead of Text.
What have I done wrong? Would it be better to do this with a Combo Box that
is preloaded with common phrases?

That would certainly be simpler for the user; use the combo's
AfterUpdate event.
I realize that I will need another command button to concatenate the date
and time to this textbox.text and then append to the [Comments] field before
adding the record to the table.

If you want to build up the Comments string directly, rather than
using an intermediate textbox, you could use code like

Private Sub cboTextBits_AfterUpdate()
Me![Comments] = Me!Comments & Me!cboTextBits
End Sub

or, to put each text bit on a new line,

Me![Comments] = Me!Comments & vbCrLf & Me!cboTextBits


John W. Vinson[MVP]
 

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