Pass object to procedure

M

Martin Dashper

Why doesn't this work?


Private Sub Button0_Click()
testSub (Controls!textBox1)
End Sub

Private Sub testSub(cName As Object)
cName.value = "Hi"
End Sub

We get error 'Object required.'

Martin Dashper
 
A

Allen Browne

The issue is with the way the variable is being passed.

Try:
Call testSub(Controls!textBox1)
or:
testSub Controls!textBox1

We find using Call to be the most consistent approach (i.e. works regardless
of whether you are calling a Function or Sub).
 

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