Passing a control as a parameter.

  • Thread starter Thread starter Geraint
  • Start date Start date
G

Geraint

Hi,

I want to write a module function that outputs an address to a text box.
The text boxes are on a number of forms so I feel that a function would be
best.

Function PopulateAddress(formName As Form, txtBoxName As TextBox)

formName!txtBoxName = "Address Details will go here!"

End Function

I know how to reference the form bit I'm not sure how to reference the text
box when calling the above function.

Private Sub Command0_Click()

PopulateAddress Me.Form, text1?

End Sub

Thanks,

Geraint
 
If you are passing a reference to the text box, you can set its Value:

Function PopulateAddress(txtBoxName As TextBox)
txtBoxName.Value = "Address Details will go here!"
End Function


If you are passing the names of the form and text box (not the objects
themselves):

Function PopulateAddress(strFormName As String, strBoxName As String)
Forms(strFormName).Controls(strBoxName).Value = "Address Details will go
here!"
End Function
 
Allen Browne said:
If you are passing a reference to the text box, you can set its Value:

Function PopulateAddress(txtBoxName As TextBox)
txtBoxName.Value = "Address Details will go here!"
End Function


If you are passing the names of the form and text box (not the objects
themselves):

Function PopulateAddress(strFormName As String, strBoxName As String)
Forms(strFormName).Controls(strBoxName).Value = "Address Details will go
here!"
End Function
 
Back
Top