Add Text with Command button

F

FrankM

I have a Form, I'll call it "4". Within this Form is a sub-Form, I'll call it
"4a". I have a couple different buttons on Form "4" which effect Form "4a" in
different ways.

One of the fields on Form "4a" has the name "comments". I want to add a
Command Button to Form "4" that when clicked puts text in the "comments"
field. Since "comments" is a text field Users will be able to enter whatever
they like but if they just want to enter the default text they can just click
the Command Button and the text will be entered.

I'm certain this is easy but for some reason I can't think of it.

Thank you!
 
F

FrankM

I should mention I tried the following in the OnClick of the Command Button
....

Forms![4]![4a]![comments] = Me.[Verified]

but that gave me an error message ... can't find the field "4a". I tried
removing the [4] and just have Forms![4a] but then I get an error mesasage
.... can't find the Form "4a".
 
M

Marshall Barton

FrankM said:
I have a Form, I'll call it "4". Within this Form is a sub-Form, I'll call it
"4a". I have a couple different buttons on Form "4" which effect Form "4a" in
different ways.

One of the fields on Form "4a" has the name "comments". I want to add a
Command Button to Form "4" that when clicked puts text in the "comments"
field. Since "comments" is a text field Users will be able to enter whatever
they like but if they just want to enter the default text they can just click
the Command Button and the text will be entered.


Me.subformcontrol.Form.Comments = "the default text"
 
F

FrankM

I did use "4" and "4a" just to describe the situation. I used the following
exact text but received an error.

Private Sub Command113_Click()
Me!frmamtcommentv4asub.Form!comments = "Verified"
End Sub

"4a" is really "frmamtcommentv4asub" and "4" is really "frmamtcommentv4a"

The error message I receive says, "Run-time error '2465': ... can't find
the field 'frmamtcommentv4asub' referred to in your expression."

Did I enter something incorrectly?
 
F

fredg

I did use "4" and "4a" just to describe the situation. I used the following
exact text but received an error.

Private Sub Command113_Click()
Me!frmamtcommentv4asub.Form!comments = "Verified"
End Sub

"4a" is really "frmamtcommentv4asub" and "4" is really "frmamtcommentv4a"

The error message I receive says, "Run-time error '2465': ... can't find
the field 'frmamtcommentv4asub' referred to in your expression."

Did I enter something incorrectly?

This part of Marsh's reply > subformcontrol <
refers not to the name of the subform but rather to the name of the
subform control on the main form into which you have placed your sub
form. By default, when you add a subform control to your main form,
Access names it "Childx". You may have changed that name. Whatever the
name is, that's the name you place in the syntax Marshall gave you.
 
F

FrankM

I completely missed that ... that made all the difference in the world. Thank
you!
 
M

Marshall Barton

FrankM said:
I did use "4" and "4a" just to describe the situation. I used the following
exact text but received an error.

Private Sub Command113_Click()
Me!frmamtcommentv4asub.Form!comments = "Verified"
End Sub

"4a" is really "frmamtcommentv4asub" and "4" is really "frmamtcommentv4a"

The error message I receive says, "Run-time error '2465': ... can't find
the field 'frmamtcommentv4asub' referred to in your expression."

Did I enter something incorrectly?


Double check that the subform ***control*** is named
frmamtcommentv4asub. The subform control name can be
different from the name of the form object it displays.
 
F

FrankM

Thank you, this worked perfectly (once I realised I had a different control
name).

Now something interesting has been posed as I'm finishing the program and
I'm not certain how this will work.

Comments may be entered in the field prior to entering the default text. The
default text should not replace the existing text but just be an addition to
it. Any thoughts?
 
F

fredg

Thank you, this worked perfectly (once I realised I had a different control
name).

Now something interesting has been posed as I'm finishing the program and
I'm not certain how this will work.

Comments may be entered in the field prior to entering the default text. The
default text should not replace the existing text but just be an addition to
it. Any thoughts?

Me!FourA.Form!Comments = Me!FourA.Form!Comments & vbNewLine & "Your
Text"

Will place the "Your Text" on the next line at the end of your
existing data.
 

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