View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob O`Bob Bob O`Bob is offline
external usenet poster
 
Posts: 16
Default pass combobox as argment to procedure

Hokievandal wrote:
I'm hungup trying to pass a combo box to a procedure with the 'Type Mismatch'
error. Here's a sample of what I'm trying to do. I think I'm passing the
string title of the cbox instead of the object.

Private Sub UserForm_Initialize()
Debug.Print "txtBox1 Name = " & Me.txtBox1.Name
Call PassTxtBox(txtBox1)
End Sub

Private Sub PassTxtBox(ByRef itxtBox As TextBox)
Debug.Print "Passed Text Box Name = " & itxtBox.Name
End Sub



Excel VBA may be a little different, but in vb6 your syntax seems to work just fine:

Option Explicit

Private Sub Form_Load()
Debug.Print "text1 Name = " & Me.Text1.Name
Call PassTxtBox(Text1)
End Sub

Private Sub PassTxtBox(ByRef itxtBox As TextBox)
Debug.Print "Passed Text Box Name = " & itxtBox.Name
Debug.Print "Passed Text Box Text = " & itxtBox.Text
End Sub

[result]
text1 Name = Text1
Passed Text Box Name = Text1
Passed Text Box Text = my text



Though personally I might leave off both the "Call" keyword and the parentheses
from that line (optional syntax)

Maybe the problem isn't the call, but in /when/ you're making it.
Is the control really fully instantiated by the time of the UserForm_Initialize event?



Bob
--