Does anyone in here have an answer? http://www.vbforums.com/showthread.p...hreadid=193229
Printable View
Does anyone in here have an answer? http://www.vbforums.com/showthread.p...hreadid=193229
I don't think you can you'd have to call the code in the module from inside the Usercontrol.
Well actually you could pass a reference of the control to a method in the module and it could work with it from there. Make sure you clean up good though.
VB Code:
'in module Private txt as textbox Public Sub AttachMe(txtbx as TextBox) Set txt=txtBox Msgbox txt.Text End Sub 'in usercontrol Private Sub UserControl_Initialize() AttachMe Text1 End Sub
It should be something along that lines, didn't test it.
It's no problem calling the code in the module, it's referencing the controls on the usercontrol that's p***ing me off. If I stop the code at runtime and look at the local variables I can see the bloody things. VB just says 'Object does not support this method...blah...blah' when I try to access Text1.Text or UserControl.Text1.Text or usrMyControl.Tex1.Text.
Just read your bit about passing it the control and that works but a single control at a time is not really an option, it's too complex for that. I'm looking for something like a form reference.
Thanks anyway, I'll just keep trying. :(
Why does the code need to be in a module? How many constituent controls are there on the Usercontrol?
For that you'd probably have to make your own control collection although that wouldn't be difficult.
You could either pass the controls collection as an object:
VB Code:
'in module Public Sub PassCol(obj As Object) Dim ctrls As Object Set ctrls = obj Dim ctrl As Control For Each ctrl In ctrls MsgBox ctrl.Name Next End Sub 'in usercontrol PassCol Controls
Or if you don't want to use the generic object then put all the controls in your own collection:
VB Code:
'in module Public Sub PassCol(col As Collection) Dim ctrls As Collection Set ctrls = col MsgBox ctrls.Count End Sub 'in usercontrol Dim col As New Collection Dim ctrl As Control For Each ctrl In Controls col.Add ctrl Next PassCol col
You beauty.
...Edneeis for President...
...Edneeis for President...
...Edneeis for President...
...Edneeis for President...
...Edneeis for President...
...Edneeis for President...
...Edneeis for President...
...Edneeis for President...
...Edneeis for President...
...Edneeis for President...
Thank you! I didn't think about passing the controls collection, I was trying to pass a reference to the whole usercontrol and dig down from there.
"No New Taxes!"
Glad I could help.