Passing a control as a parameter.

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
 
A

Allen Browne

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
 
K

Khim

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
 

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