Function unable to return Collection object

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Hi,

Here is a small segment of my code :
"
Sub SeedOPErrs()

Dim a As Collection
a = rFunction() ' <----VBA editor returns an error "Argument not
optional"
' when I attempt to run SeedOPErrs

End Sub

Function rFunction() As Collection

Dim a As New Collection
a.Add "GT"

rFunction = a

End Function

"

What is wrong with the code above ? Why is there an error "Argument not
optional" ??!! I stared at my screen for hours ...and i still cannot figure
out !!
Thanks in advance !!!

Regards,
Adrian
 
Sub SeedOPErrs()

Dim a As Collection
Set a = rFunction
For Each itm In a
Debug.Print itm
Next

End Sub

Function rFunction() As Collection
Dim a As New Collection

a.Add "GT"
Set rFunction = a


End Function
 
Thanks a million ! It works!
Tom Ogilvy said:
Sub SeedOPErrs()

Dim a As Collection
Set a = rFunction
For Each itm In a
Debug.Print itm
Next

End Sub

Function rFunction() As Collection
Dim a As New Collection

a.Add "GT"
Set rFunction = a


End Function
 

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

Back
Top