Does anyone know if :
1. You can pass controls through to functions and change their properties.
2. How to do it!
Cheers Guys...
Printable View
Does anyone know if :
1. You can pass controls through to functions and change their properties.
2. How to do it!
Cheers Guys...
O.K.
The simplist way of doing this is to have a parameter in you function that is of type OBJECT. Say you have a control on your form, such as TEXT1, and a function called ChangeText that you want to alter the text property of the control. This example calls the function in the Form_Load event.
Sub Form_Load()
dim boolResult as Boolean
boolResult = ChangeText(TEXT1)
end sub
Public Function ChangeText(TextControl as Object) as Boolean
TextControl.Text = "My New Text"
ChangeText = True
End Function
use TypeName to check of the Object passed is a TextBox
i.e.
if TypeName(Object)="TextBox" then
...
end if
td.
You can also specify the type as Control.
Code:Sub Change(ctl As Control)
If TypeOf ctl Is TextBox Then ctl = "HELLO"
End Sub
Cheers fellas that has got me sorted!