Pass object to procedure

  • Thread starter Thread starter Martin Dashper
  • Start date Start date
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
 
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).
 
Back
Top