Results 1 to 6 of 6

Thread: Referencing controls

  1. #1

    Thread Starter
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282

    Referencing controls

    Does anyone in here have an answer? http://www.vbforums.com/showthread.p...hreadid=193229
    That's Mr Mullet to you, you mulletless wonder.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 'in module
    2. Private txt as textbox
    3.  
    4. Public Sub AttachMe(txtbx as TextBox)
    5.    Set txt=txtBox
    6.    Msgbox txt.Text
    7. End Sub
    8.  
    9. 'in usercontrol
    10. Private Sub UserControl_Initialize()
    11.    AttachMe Text1
    12. End Sub

    It should be something along that lines, didn't test it.
    Last edited by Edneeis; Aug 20th, 2002 at 03:59 AM.

  3. #3

    Thread Starter
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    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.
    That's Mr Mullet to you, you mulletless wonder.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 'in module
    2. Public Sub PassCol(obj As Object)
    3.     Dim ctrls As Object
    4.     Set ctrls = obj
    5.     Dim ctrl As Control
    6.     For Each ctrl In ctrls
    7.         MsgBox ctrl.Name
    8.     Next
    9. End Sub
    10.  
    11. 'in usercontrol
    12. PassCol Controls

    Or if you don't want to use the generic object then put all the controls in your own collection:
    VB Code:
    1. 'in module
    2. Public Sub PassCol(col As Collection)
    3.     Dim ctrls As Collection
    4.     Set ctrls = col
    5.     MsgBox ctrls.Count
    6. End Sub
    7.  
    8. 'in usercontrol
    9.     Dim col As New Collection
    10.     Dim ctrl As Control
    11.     For Each ctrl In Controls
    12.         col.Add ctrl
    13.     Next
    14.     PassCol col

  5. #5

    Thread Starter
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    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.
    That's Mr Mullet to you, you mulletless wonder.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    "No New Taxes!"

    Glad I could help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width