0
Function printerpart(outputtext As Collection) As Collection
    Dim TotalRecords As Integer 'Original build didn't include this line; no other declaration of TotalRecords, though?
    Set TotalRecords = outputtext.Count
    For i = 1 To TotalRecords
        outputext = outputtext(i)
        outputext = Replace(outputext, "&", "and")
        Print #1, outputext
    Next i
    Set printerpart = New Collection
End Function

When attempting to run this function, an error occurs on the line assigning a value/object to TotalRecords. Initial builds did not include the Set statement on that line, but failing to include it results in RTE 91. With Set, however, the function encounters a compile-time error: Object Required.

Each call to printerpart passes outputtext as a collection of string objects.

I am aware of how terrible the variable names are and intend to fix them.

This question seems to imply that the Set statement should only be used to assign Object variables, and that lacking it is the cause of RTE 91 in most cases. Does declaring TotalRecords as an Integer make it an object? The same errors occur if TotalRecords is not declared until its assignment statement.

What is the proper method for resolving these errors in this context, given that the commonly suggested fix for one issue causes the other?

Community
  • 1
  • 1

1 Answers1

2

When you remove the "set" the error you get is not according to TotalRecords, it refers to outputtext, seems like what you are passing to function does not have the .count property, check again the variable passed to the function please

KKowalczyk
  • 333
  • 2
  • 7
  • Collections do have the `.count` property so `outputtext` must be `Nothing` – Sobigen May 22 '15 at 12:55
  • After enclosing the function contents in `If (Not outputtext Is Nothing Then`, the same error occurs, so I believe we can rule out outputtext being `Nothing`; unless I'm misunderstanding that conditional, of course. – Nathaniel Bendinsky May 22 '15 at 13:06
  • and did you remove the "set" before "totalrecords?" – KKowalczyk May 22 '15 at 13:08
  • Doh! Well, that part of the method runs cleanly now, at least. There are still errors, but I'm not sure whether they merit a fresh post; should I open a new question for another RTE 91 in a different part of the file? It's showing up on a call to Collection.Add now. – Nathaniel Bendinsky May 22 '15 at 13:15
  • think you should:) it might get confusing for discussion new joiners – KKowalczyk May 22 '15 at 13:17