Access VBA - Changing TextBox value from within a function (ByRef)

Zephram picture Zephram · Jun 5, 2013 · Viewed 58.2k times · Source

I'm trying to write a sub that will get two parameters - a textbox in a form and a text. My intention is that the function will append the text into any textbox.

Sub AppendTextBox([any textbox in my form], text As String)

[code that appends the text parameter to the textbox]

End Sub

Please note that I'm not trying to append text to a specific textbox, but to create a function that can receive any textbox in the form and append it with any text.

Thanks for your help.

Answer

Zephram picture Zephram · Jun 11, 2013

I've found the answer and it's much simpler than I though it is:

Private Sub AAA(A)

A.Value = "Desired text"

End Sub

Or if you want to append:

Private Sub AAA(A)

A.Value = A.Value & vbnewline & "Desired text"

End Sub