Button in subform, inserting text string into field on Parent form

  • Thread starter Thread starter Toucan
  • Start date Start date
T

Toucan

Dear all.

I have a form with memo fields and it contains a subform with buttons to
insert boilerplate text into the fields in the parent form.

See the code:

Private Sub CommandFair_Click()
Dim str As String
str = "fair"
Screen.PreviousControl = Screen.PreviousControl & str & " "
Screen.PreviousControl.SetFocus
End Sub

What is happening is that the first time I click on a different button I get
an error message.

Any thoughs?
Thanks.
 
If you are in a subform, you can refer to the parent form with the Parent
object.

Private Sub CommandFair_Click()
Dim str As String
str = "fair"
Parent!MyField = Parent!MyField & str & " "
Parent!MyField.SetFocus
End Sub
 
My parent form has several fields and I'd like to be able to insert the
string in whatever field the cursor is.

Thoughts?

Thanks!
Niels
 
Back
Top