I am trying to pass a custom object to method but I get the following error "object doesn't support this property or method" when I call the myCourseObj.FileInSemesterCollection (myCourseSectionObj) method. I do not think I have misspelled anything. I rewrote the sub declaration but received the same error. Could someone tell me what is wrong?
Module 1 Code
Option Explicit
Public currentSection As SectionObj
Public Sub CreateCourseObjs(sectionWrksht As Worksheet) 'Run this Sub
'Determine the number of rows with section information
Dim myRng As Range
'ThisWorkbook.Worksheets("CATSUMMER").Activate
sectionWrksht.Activate
'Call FindNumUsedRows(ThisWorkbook.Worksheets("CATSUMMER"))
Dim numOfDataRows As Long
'numOfDataRows = FindNumUsedRows(ThisWorkbook.Worksheets("CATSUMMER"))
numOfDataRows = FindNumUsedRows(sectionWrksht)
Dim numOfDataCols As Long
'numOfDataRows = FindNumUsedRows(ThisWorkbook.Worksheets("CATSUMMER"))
numOfDataCols = FindNumUsedCols(sectionWrksht)
'MsgBox ("numOfDataRows: " & numOfDataRows)
'The loop starts at 2 to skip the header row
Dim row_counter As Long
Dim col_counter As Long
Dim cellValueStr As String
For row_counter = 2 To numOfDataRows Step 1
Set currentSection = New SectionObj
cellValueStr = CStr(sectionWrksht.Cells(row_counter, 1).Value)
currentSection.CourseSections = CStr(sectionWrksht.Cells(row_counter, 1).Value)
currentSection.Term = CStr(sectionWrksht.Cells(row_counter, 2).Value)
currentSection.SectionName = CStr(sectionWrksht.Cells(row_counter, 3).Value)
currentSection.Subject = CStr(sectionWrksht.Cells(row_counter, 4).Value)
currentSection.SectionNum = CStr(sectionWrksht.Cells(row_counter, 5).Value)
currentSection.InstrMethod = CStr(sectionWrksht.Cells(row_counter, 6).Value)
currentSection.MinCred = CStr(sectionWrksht.Cells(row_counter, 7).Value)
currentSection.StartDate = CStr(sectionWrksht.Cells(row_counter, 8).Value)
currentSection.EndDate = CStr(sectionWrksht.Cells(row_counter, 9).Value)
currentSection.Depts = CStr(sectionWrksht.Cells(row_counter, 10).Value)
currentSection.SecFacultyLastName = CStr(sectionWrksht.Cells(row_counter, 11).Value)
currentSection.SecFacultyFirstName = CStr(sectionWrksht.Cells(row_counter, 12).Value)
currentSection.ShortTitle = CStr(sectionWrksht.Cells(row_counter, 13).Value)
currentSection.Status = CStr(sectionWrksht.Cells(row_counter, 14).Value)
currentSection.AddedOn = CStr(sectionWrksht.Cells(row_counter, 15).Value)
currentSection.Column1 = CStr(sectionWrksht.Cells(row_counter, 16).Value)
sectionsAllCollection.Add Item:=currentSection, Key:=currentSection.CourseSections
Call FileSection(currentSection)
Next row_counter
Private Sub FileSection(myCourseSectionObj As SectionObj)
Dim myCourseObj As CourseObj
'Need to test for "Null" also
If (StrComp(myCourseSectionObj.Column1, "Error", vbTextCompare) <> 0) Then
Dim mySubject As String
mySubject = CStr(myCourseSectionObj.Subject)
'Check to see if the key (name of course) is already in the collection
Dim InCollection As Boolean
InCollection = myCollectionChecker.CheckCollection(myCourseObjCollection, mySubject)
'Course name is not in the collection
If (Not InCollection) Then
Set myCourseObj = New CourseObj
myCourseObj.Subject = myCourseSectionObj.Subject
myCourseObj.FileInSemesterCollection (myCourseSectionObj) 'Error is generated on this line
myCourseObjCollection.Add Item:=myCourseObj, Key:=myCourseObj.Subject
'Course name is in the collection
Else
myCourseObjCollection.Item(myCourseObj.Subject).FileInSemesterCollection (myCourseSectionObj)
End If
Else
End If
End Sub
CourseObj Class Module
Option Explicit
Private subjectStr As String
Private semesterCollection As Collection
Private myCollectionChecker As CollectionChecker
Private Sub Class_Initialize()
Subject = ""
Set semesterCollection = New Collection
Set myCollectionChecker = New CollectionChecker
End Sub
Public Sub FileInSemesterCollection(mySectionObj1 As SectionObj)
Dim InCollection As Boolean
InCollection = myCollectionChecker.CheckCollection(semesterCollection, mySectionObj1.Column1)
'If the semesterObj has not been created for the particular course name
If (Not InCollection) Then
Dim mySemesterObj As SemesterObj
mySemesterObj = New SemesterObj
mySemesterObj.FileInCollegesCollection (mySectionObj1)
semesterCollection.Add Item:=mySemesterObj, Key:=mySectionObj1.Column1
Else
'The semesterObj already exist, so just file the section in the semester
semesterCollection.Item(mySectionObj1.Column1).FileInCollegesCollection (mySectionObj1)
End If
End Sub
Public Property Get Subject() As String
Subject = subjectStr
End Property
Public Property Let Subject(ByVal mySubjectStr As String)
subjectStr = mySubjectStr
End Property
SectionObj Class Module
Option Explicit
Private courseSectionsStr As String
Private termStr As String
Private sectionNameStr As String
Private subjectStr As String
Private sectionNumStr As String
Private instrMethodStr As String
Private minCredStr As String
Private startDateStr As String
Private endDateStr As String
Private deptsStr As String
Private secFacultyLastNameStr As String
Private secFacultyFirstNameStr As String
Private shortTitleStr As String
Private statusStr As String
Private addedOnStr As String
Private column1Str As String
Private Sub Class_Initialize()
courseSectionsStr = ""
termStr = ""
sectionNameStr = ""
subjectStr = ""
sectionNumStr = ""
instrMethodStr = ""
minCredStr = ""
startDateStr = ""
endDateStr = ""
deptsStr = ""
secFacultyLastNameStr = ""
secFacultyFirstNameStr = ""
shortTitleStr = ""
statusStr = ""
addedOnStr = ""
column1Str = ""
End Sub
Public Property Get CourseSections() As String
CourseSections = courseSectionsStr
End Property
Public Property Let CourseSections(ByVal myCourseSection As String)
courseSectionsStr = myCourseSection
End Property
Public Property Get Term() As String
Term = termStr
End Property
Public Property Let Term(ByVal myTerm As String)
termStr = myTerm
End Property
Public Property Get SectionName() As String
SectionName = sectionNameStr
End Property
Public Property Let SectionName(ByVal mySectionNameStr As String)
sectionNameStr = mySectionNameStr
End Property
Public Property Get Subject() As String
Subject = subjectStr
End Property
Public Property Let Subject(ByVal mySubjectStr As String)
subjectStr = mySubjectStr
End Property
Public Property Get SectionNum() As String
SectionNum = sectionNumStr
End Property
Public Property Let SectionNum(ByVal mySectionNumStr As String)
sectionNumStr = mySectionNumStr
End Property
Public Property Get InstrMethod() As String
InstrMethod = instrMethodStr
End Property
Public Property Let InstrMethod(ByVal myInstrMethodStr As String)
instrMethodStr = myInstrMethodStr
End Property
Public Property Get MinCred() As String
MinCred = minCredStr
End Property
Public Property Let MinCred(ByVal myMinCredStr As String)
minCredStr = myMinCredStr
End Property
Public Property Get StartDate() As String
StartDate = startDateStr
End Property
Public Property Let StartDate(ByVal myStartDateStr As String)
startDateStr = myStartDateStr
End Property
Public Property Get EndDate() As String
EndDate = endDateStr
End Property
Public Property Let EndDate(ByVal myEndDateStr As String)
endDateStr = myEndDateStr
End Property
Public Property Get Depts() As String
Depts = deptsStr
End Property
Public Property Let Depts(ByVal myDeptsStr As String)
deptsStr = myDeptsStr
End Property
Public Property Get SecFacultyLastName() As String
SecFacultyLastName = secFacultyLastNameStr
End Property
Public Property Let SecFacultyLastName(ByVal mySecFacultyLastNameStr As String)
secFacultyLastNameStr = mySecFacultyLastNameStr
End Property
Public Property Get SecFacultyFirstName() As String
SecFacultyFirstName = secFacultyFirstNameStr
End Property
Public Property Let SecFacultyFirstName(ByVal mySecFacultyFirstNameStr As String)
secFacultyFirstNameStr = mySecFacultyFirstNameStr
End Property
Public Property Get ShortTitle() As String
ShortTitle = shortTitleStr
End Property
Public Property Let ShortTitle(ByVal myShortTitleStr As String)
shortTitleStr = myShortTitleStr
End Property
Public Property Get Status() As String
Status = statusStr
End Property
Public Property Let Status(ByVal myStatusStr As String)
statusStr = myStatusStr
End Property
Public Property Get AddedOn() As String
AddedOn = addedOnStr
End Property
Public Property Let AddedOn(myAddedOnStr As String)
addedOnStr = myAddedOnStr
End Property
Public Property Get Column1() As String
Column1 = column1Str
End Property
Public Property Let Column1(ByVal myColumn1Str As String)
column1Str = myColumn1Str
End Property
Bookmarks