hey,why i can't pass a control to a function?

M

microsoft news

thank you looking at my post

i have a problem to pass a control to a function,here is my code:

Public Sub getmaterialSql(ByRef combobox1 As combobox)
Dim id As Integer

If IsNull(combobox1.Value) Then
MsgBox ("Can not be Null")
Exit Sub
Else
id = cint(combobox1.Value)
End If
.....
....
End Sub


when i refer such a function,The error occurs: it says "can not find object"
 
A

Albert D.Kallal

What you have looks just fine...so, You will have to show your calling
code.....

Note that you need to use

Call getmaterialSql(me.MyComboBox)

You can also use

getmaterial me.mycombobox

However, you can NOT use

getmaterial (me.mycombobox)

The above brackets will force the expression to be calculated and evaluated
BEFORE it is passed to the routine. That means you are actually going to
wind up passing a int, or string type value...not the actual combo box
control...

For this reason, I would adopt a consistent coding standard, and always use
the Call YourSubName syntax....
 
D

Douglas J Steele

See whether using

Public Sub getmaterialSql(ByRef combobox1 As Control)

works any better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top