TheSwamp

Code Red => VB(A) => Topic started by: Columbia on June 29, 2004, 11:39:52 AM

Title: Passing controls...
Post by: Columbia on June 29, 2004, 11:39:52 AM
Okay, here is my next question...

How do I pass a Form Control Object to a processing function?

I have a comboList control that I want to enable with the following function.

Code: [Select]

Public Function Enable_List(ByRef whichList As ListBox)
    whichList.Enabled = True
    whichList.ForeColor = &H80000008
End Function


Now in my Form Code i have this...

Code: [Select]

...
With UserForm1
    Enable_List (.comboListbox1)
End With
...


However, when I run my code I keep getting an Object Required error.  Mainly, because I think the argument to the function call is getting "", which is the default value of the comboList, not the comboList Control Object itself.  Does this make any sense?

So how do I get VBA to pass the object itself?
Title: Passing controls...
Post by: hendie on June 29, 2004, 11:47:12 AM
have you tried
Code: [Select]
Public Function Enable_List(whichList As ListBox)
    whichList.Enabled = True
    whichList.ForeColor = &H80000008
End Function


and
Code: [Select]

    Enable_List comboListbox1
Title: Passing controls...
Post by: Columbia on June 29, 2004, 12:13:20 PM
Thanks,

That help me figure it out.  It would also help, if I typed the function correctly.  It wouldn't work, because I was trying to send the Enable function a combobox not a listbox.

But I've got it now.  Thanks!