By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Reverting value to previous after toggle is deselected

P: 1
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("Management 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.Value Then
Sem1Cred.Value = Sem1Cred.Value + Sem1CredVal
If Sem2Cred.Value + Sem2CredVal <= Sem2TotCred.Value Then
Sem2Cred.Value = Sem2Cred.Value + Sem2CredVal
Else
Call MsgBox("You cannot select more than a total of " & Sem2TotCred.Value & " credits in semester 2", vbExclamation, "ERROR")
ManDisTog.Value = False
End If
Else
Call MsgBox("You cannot select more than a total of " & Sem1TotCred.Value & " credits in semester 1", vbExclamation, "ERROR")
ManDisTog.Value = False
End If

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

Case 2
ManDisTog.Value = False

End Select

End If

End Sub
Dec 23 '16 #1
Share this Question
Share on Google+
1 Reply


PhilOfWalton
Expert 100+
P: 1,430
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
Dec 26 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.