How to use VBA/API to enroll a student in a class

This article contains sample code using the API to enroll a student in a class. 
This can be accomplished by following the example code in this solution.

Public Sub AddClass()
       
    Dim lSessionID As Long
    Dim lTermID As Long
    Dim lSchoolID As Long
    Dim lCourseID As Long
    Dim sTermDesc As String  
    Dim oServices As FE_Services
    Dim oUtility As IBBUtilityCode
    Dim oClass As cEAClass
    Dim oClassTerm As cEAClassTerm
    Dim oSC As IBBSessionContext
   
    Set oSC = FE_Application.SessionContext
    
    Set oServices = New FE_Services
    oServices.Init oSC

    Set oUtility = oServices
   
    lCourseID = 58
    lSessionID = oUtility.eaSessionsGetSessionID("Regular", "Middle", "2009-2010", True)
    lSchoolID = oUtility.eaGetSchoolFromSession(lSessionID)
    lTermID = oUtility.eaGetTermByDate(lSchoolID, "10/1/2009")
    sTermDesc = oUtility.eaTermsGetTermDescription(lTermID)
   
    ''Debug.Print lSessionID
    ''Debug.Print lSchoolID
    ''Debug.Print lTermID
    ''Debug.Print lCourseID
   
    Set oUtility = Nothing
    oServices.CloseDown
    Set oServices = Nothing
   
    On Error GoTo EH
   
    Set oClass = New cEAClass
    oClass.Init oSC
   
    oClass.Fields(EACLASSES_fld_EA7COURSESID) = lCourseID
    oClass.Fields(EACLASSES_fld_STARTTERM) = lTermID
    oClass.Fields(EACLASSES_fld_EA7SESSIONSID) = lSessionID
   
    oClass.LoadTermsForCourse lTermID

    oClass.Save
   
'' How to set the ENROLL flag

With theClass.ClassStudents().Add(theClass.Fields(EEACLASSESFields.EACLASSES_fld_STARTTERM))
.Fields(EEAClassStudentFields.EACLASSSTUDENT_fld_EA7STUDENTID) = student.Fields(EEASTUDENTSFields.EASTUDENTS_fld_EA7STUDENTSID)
With .ClassStudentTerms().Item(1)
.SetClassTermFromTerm(theClass.Fields(EEACLASSESFields.EACLASSES_fld_STARTTERM))
.Fields(eEAClassStudentTermsFields.EACLASSSTUDENTTERM_fld_ENROLLED) = bbTF.bbTrue
End With
End With
student.Save()
theClass.Save()

End Sub


Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Our Customer Support can help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality. If you are interested in learning more about the VBA and API modules, contact your account manager.

Environment

 Education Edge

Was this article helpful?