Hi,
I'm trying to do something which I feel should be very simple: pass a reference to a textbox control into function. I want to do something very much like this:
------------------------------------------------------------------------
Public Sub DisplayText(txtBox As Textbox, text As String)
txtBox.Text = text
End Sub
Public Sub Button1_Click()
DisplayText(Me.TextBox1, "Hello World")
End Sub
------------------------------------------------------------------------
As you'd imagine, I'd expect that to make TextBox1 say "Hello World' when I click Button1, but it's doesn't. The problem is that Me.TextBox1 returns the default value of the textbox, not the textbox itself, so I'm passing in two strings to DisplayTextBox - whatever the user entered in Textbox1 and "Hello World", and this results in an error.
I've been searching and searching but I can't find a way to pass a reference to the actual textbox control. I've tried:
-Me![TextBox1]
-Forms![MyForm]![TextBox1]
-Me.Controls.Item("TextBox1")
and a bunch of other stuff. Is there a way?
SomeValue = fnYourFunction(Me.TextboxN
'The function
Public Sub fnYourFunction(sTextBoxNam
'do your stuff
End Sub
It is not necessary to pass the TextBox object, just it's value as a string.