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
    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

'' How to set the ENROLL flag

With theClass.ClassStudents().Add(theClass.Fields(EEACLASSESFields.EACLASSES_fld_STARTTERM))
With .ClassStudentTerms().Item(1)
.Fields(eEAClassStudentTermsFields.EACLASSSTUDENTTERM_fld_ENROLLED) = bbTF.bbTrue
End With
End With

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.


 Education Edge

Was this article helpful?

Thanks for your feedback! Did this solve your issue?

Comments (optional):

Thanks for your feedback!
We're glad it was helpful but sorry it didn’t solve your issue. If you need assistance, click Chat with Support below.
We’re sorry to hear that. Please tell us why.

 I don't like how this works.

 The answer is confusing.

 The answer didn't match what I was searching for.

Additional Comments (optional):

Thanks for your feedback! If you need assistance, click Chat with Support below.
Thanks for your feedback. Help us make our products even better by sharing details in our Idea Banks or our online Community.
Thanks for letting us know. We'll work on clarifying the information in the article. If you need assistance, click Chat with Support below.
Thanks for letting us know. We'll work on updating the search engine to return more relevant results.