Increment Student Signup based on Different Course Number

I have two forms:(1) Course Announcement

(2) Course Registration

Form (1) Course Announcement may have several documents with different Course Numbers such as

MM23, MM24.

When students signs up for course # MM23 with form (2) Course Registration, I need to auto asign signUp number based on course # MM23

When students SignUp for course # MM24, the SignUp number starts from 1 again and increments as SignUp increases.

My code below only works on just the first Course Number (MM23) but When another student clicks on a different course number it does not assign a new signup number based on the actual course # instead it just increments the first Course # MM23 above.

I would appreciate your ideas.

Sub Click(Source As Button)

Dim s As New NotesSession

Dim theValue As String

Set s = New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim dc As NotesDocumentCollection

Dim key1 As NotesItem

Dim item As NotesItem

Dim keyString As String

Dim SignUp As Integer

Set db = S.CurrentDatabase

'----------------------------

'Get an environment value

'Update ‘(ClassSignUp)’ view with the number of student signed up

'-------------------------------------

theValue = s.GetEnvironmentString( “caCourseNumber” )

Msgbox "The current Course Number is : " & theValue

’ the view contains Class Announcement

Set view = db.GetView(“(ClassSignUp1)”)

Set dc = view.GetAllDocumentsByKey( theValue , False)

Set doc = dc.GetFirstDocument

'If doc Is Nothing Then

Do Until doc Is Nothing

SignUp = doc.caStudentSignUp(0)

SignUp = SignUp + 1

Set item = doc.ReplaceItemValue(“caStudentSignUp”, SignUp)

Call doc.Save(False, True)

Set doc= dc.GetNextDocument(doc)

Loop

'Compose Course Registration

Dim workspace As New NotesUIWorkspace

answer = Msgbox(“Are you sure you want to register for this class ?”, 4, “Register for this class ?”)

If answer = “6” Then

Call workspace.ComposeDocument( “”, “”, “Course Registration” )

End If

End Sub