Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grading 3

Status
Not open for further replies.

cantech2

Instructor
Oct 18, 2003
21
US
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
 
Hi,

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.

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

Thanks,
Cantech2
 
Then you'll need to do it in a query. Something like:

IIF([ScoreFieldName] < 60, &quot;F&quot;, iif([ScoreFieldName] < 70, &quot;D&quot;, iif([ScoreFIeldName] < 80, &quot;C&quot;, iif([ScoreFieldName] < 90, &quot;B&quot;, iif([ScoreFieldName] <= 100, &quot;A&quot;, &quot;Invalid Score&quot;)))))

Some SQL supports Case Statements, but I don't think Access does (sure would be nice!!).

HTH

Leslie
 
Why not have a table

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.

John
 
This also looks like a good canidate for the oft overlooked Switch function
Code:
Grade = Switch(Score < 60, &quot;F&quot;, _
               Score >= 60 And Score < 70, &quot;D&quot;, _
               Score >= 79 And Score < 80, &quot;C&quot;, _
               Score >= 80 And Score < 90, &quot;B&quot;, _
               Score > 89, &quot;A&quot;)
And this function can be used in a ControlSource, something like the following:
Code:
=Switch([txtScore]<60,&quot;F&quot;,[txtScore]>=60 And [txtScore]<70,&quot;D&quot;,[txtScore]>=70 And [txtScore]<80,&quot;C&quot;,[txtScore]>=80 And [txtScore]<90,&quot;B&quot;,[txtScore]>89,&quot;A&quot;)

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks CajunCenturion,

the switch function you gave was simple and perfect for my purpose.

God bless you,
Cantech2
 
You're quite welcome cantech2.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Next question:

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top