Public Function RETURN_Equipment(Optional category As String) As Collection Dim config As classConfiguration Set config = New classConfiguration Dim item As classItem Set item = New classItem Dim myCollection As Collection Set myCollection = New Collection For Each config In Configurations For Each item In config.colItems If IsMissing(category) Then myCollection.add item ElseIf InStr(category, "mainframe") <> 0 And item.category = "mainframe" Then myCollection.add item MsgBox "Fired!" ElseIf category = "accessory" And item.category = "accessory" Then Else End If Next Next RETURN_Equipment = myCollection End Function I keep getting
Compile error:
Argument not optional
I get the error on the last line
RETURN_Equipment = myCollection I understand the error message, its telling me I did not fill out a parameter. But I only have one parameter, and I've declared it optional. It looks like the code thinks I'm trying to call the function from the function?
What gives?
.Itemwhich requires an index. To assign the reference of the collection object to a variable you need to use theSetkeyword at the start of the line.