Hello,
I am having a problem returning a collection from a function that is in a class.
Basically, the function gets a set of comments from a database and sticks them in a collection, then I loop thru the collection and fill a listbox. However, when I run the program, the sub that calls the function that returns the collection throws an error that says, "Compile Error Type Mismatch". I am not sure how there can be a type mismatch. The variable that holds the returned collection is dimed as a collection. My code is below. The part in red is highlighted when the error is thrown.
Here is the code that gets called.Code:Private Sub cmdAddComment_Click() On Error GoTo ErrorHandler If Settings.REPORT_OPEN = True And Settings.ReportControl.REPORT_SAVED = True Then Dim CommentCol As New Collection Select Case Settings.OPEN_REPORT_NAME Case Is = 0 Set CommentCol = Settings.ReportControl.DataControl.GetCommentsBySubFunction(Settings.ReportControl.DataControl.GetSubFunctionIDFromCollection(Settings.ReportControl.DataControl.SUBFUNINDEX_INDEX), False) Case Is = 1.........
Thank you for your help.Code:Public Function GetCommentsBySubFunction(ByVal ParentID As Long, ByVal MultiTransactions As Boolean) As Collection On Error GoTo ErrorHandler If MultiTransactions <> True Then Me.OpenDatabase End If Dim A As New Collection DataTable.TableName = "Comment" DataTable.Open DataTable.IndexName = "IndexPosition" DataTable.IndexAscending DataTable.Query "PID = " & "'" & ParentID & "'" Me.ReleaseComments If DataTable.QueryRowCount <> 0 Then Settings.ReportControl.DataControl.COMMENT_INDEX = 1 While Not DataTable.EOF = True A.Add Trim$(Replace(DataTable.GetString("Comment"), Chr$(0), vbNullString)) DataTable.Next Wend Else A.Add "No pre-defined comments available." End If DataTable.Close Set GetCommentsBySubFunction = A Set A = Nothing If MultiTransactions <> True Then Me.ReleaseDatabase End If Exit Function ErrorHandler: ErrorAlert.ErrorAlert Err.Number, Err.Description, "clsTableControl.GetCommentsBySubFunction" End Function




Reply With Quote