In Microsoft Access, on a form where there is a score field and a grade field, how do I program the grade field to automatically display A, B, C, D, E or F depending on the value in the grade field
Do you mean "... depending on the value in the score field" - this would make more sense.
If this is the case, right click on the score field, choose Build Event then Code Builder.
You will end up with something like
Private Sub txtScore_BeforeUpdate (Cancel As Integer)
End Sub
On the right hand drop down box, change BeforeUpdate to AfterUpdate, and the following lines will come up:
Private Sub txtScore_AfterUpdate ()
End Sub
You can delete the earlier lines as it is not needed in this case, and put the following code in between the lines:
Code:
Dim intScore As Integer
If IsNumeric (txtScore) Then
intScore = Val (txtScore)
Select Case intScore
Case 1 To 40
txtGrade = "F"
Case 41 To 50
txtGrade = "E"
Case 51 To 60
txtGrade = "D"
Case 61 To 70
txtGrade = "C"
Case 71 To 80
txtGrade = "B"
Case 81 To 100
txtGrade = "A"
Case Else
txtGrade = "Invalid"
End Select
Else
MsgBox "Score is not a numeric value"
End If
You will need to change in the code:
txtScore to the name of the textbox that holds the score.
txtGrade to the name of the textbox that holds the grade.
You may also want to change the ratings that give different scores.
Dear Jrbarnett,
thanks for your last response. Was wonderful.
Next issue:
I could implement the event on the form. However, the grades do not show up on a report and I dont see the option to build an event there. How can I get the grades to function in a report.
MinScore, MaxScore, Grade and join this on the value >= Minscore and < MaxScore, which would give you an easy way of changing it.
You can join this in a query which can be used in a report.
And this function can be used in a ControlSource, something like the following:
Code:
=Switch([txtScore]<60,"F",[txtScore]>=60 And [txtScore]<70,"D",[txtScore]>=70 And [txtScore]<80,"C",[txtScore]>=80 And [txtScore]<90,"B",[txtScore]>89,"A")
Good Luck
-------------- As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
Now, on the same report, assume Jack, Jill and Bill are in a class and they all take Chemistry. Jack has 70% with grade A, Jill has 45% with grade D and Bill has 65% with grade B. Each of them has their reports on a separate page because I asked for a page break after each students details. The scores and grading work fine.
My question is, how do I make a field called POSITION to show that Jack was 1st, Jill was 3rd and Bill was 2nd so that I can easily print each students report. And if 2 students have the same score, they should have same position.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.