Reverting value to previous after toggle is deselected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luke123
    New Member
    • Dec 2016
    • 1

    Reverting value to previous after toggle is deselected

    Hello

    I'm developing a form that allows students to choose university module choices. I have a credit counter which keeps a running total of all selected modules credits. A module cannot be selected if it exceeds the credit limit for each semester.

    One module is 'Management Dissertation' which is either worth 10 credits in semester 1 and 20 credits in semester 2 OR 20 credits in semester 1 and 10 credits in semester 2. Upon clicking the module, a yes/no/cancel msgbox appears asking which option they'd like - it updates the credits counter accordingly. However, I'm struggling to find a way of deducting those credits if the module is deselected.

    This is my code so far - any thoughts?

    'Management Dissertation

    Private Sub mandistog_click ()

    Dim Response3
    Dim Sem1CredVal As Integer
    Dim Sem2CredVal As Integer

    If ManDisTog.Value = True Then
    Response3 = MsgBox("Managem ent Dissertation can be counted as EITHER:" & Chr(13) & "a) 10 credits in Semester One and 20 credits in Semester Two" & Chr(13) & "OR" & Chr(13) & "b) 20 credits in Semester One and 10 credits in Semester Two" & Chr(13) & Chr(13) & "Click 'Yes' for option a) or 'No' for option b)", 35, "ALERT")
    Select Case Response3

    Case 6
    Sem1CredVal = 10
    Sem2CredVal = 20
    If Sem1Cred.Value + Sem1CredVal <= Sem1TotCred.Val ue Then
    Sem1Cred.Value = Sem1Cred.Value + Sem1CredVal
    If Sem2Cred.Value + Sem2CredVal <= Sem2TotCred.Val ue Then
    Sem2Cred.Value = Sem2Cred.Value + Sem2CredVal
    Else
    Call MsgBox("You cannot select more than a total of " & Sem2TotCred.Val ue & " credits in semester 2", vbExclamation, "ERROR")
    ManDisTog.Value = False
    End If
    Else
    Call MsgBox("You cannot select more than a total of " & Sem1TotCred.Val ue & " credits in semester 1", vbExclamation, "ERROR")
    ManDisTog.Value = False
    End If

    Case 7
    Sem1CredVal = 20
    Sem2CredVal = 10
    If Sem1Cred.Value + Sem1CredVal <= Sem1TotCred.Val ue Then
    Sem1Cred.Value = Sem1Cred.Value + Sem1CredVal
    If Sem2Cred.Value + Sem2CredVal <= Sem2TotCred.Val ue Then
    Sem2Cred.Value = Sem2Cred.Value + Sem2CredVal
    Else
    Call MsgBox("You cannot select more than a total of " & Sem2TotCred.Val ue & " credits in semester 2", vbExclamation, "ERROR")
    ManDisTog.Value = False
    End If
    Else
    Call MsgBox("You cannot select more than a total of " & Sem1TotCred.Val ue & " credits in semester 1", vbExclamation, "ERROR")
    ManDisTog.Value = False
    End If

    Case 2
    ManDisTog.Value = False

    End Select

    End If

    End Sub
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    #2
    Have you thought of using check boxes and assigning the Credit values depending on which (if any) are chosen. In your code have a variable called "ErrorCondition " which gets set every time one of the checkboxes is updated, and gets unset only if the credits are within your limits. If the ErrorCondition persists, clear the check boxes and the student has to go round the loop again.

    Phil

    Comment

    Working...