473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

I need to create class exam position

I am working on access database and need to give each student position based on their score in class.

For example:
A class with 5 students with the following scores:
Student Score
Student A: 32
Student B: 78
Student C: 90
Student D: 90
Student E: 21

I wish to generate their position thus:
Student Position in Calss
Student A: 4
Student B: 2
Student C: 1
Student D: 1
Student E: 5

Take note of the tie between Student C and D please.

Thank you.
Dec 29 '06 #1
12 3618
Kosmos
153 100+
here's one solution

You could sort their final grades in descending order. We'll call this tblStudents which is divided into fields Students and StudentScore and Ranking

Create a form and a command button. Don't assign any of the wizard stuff but just click cancel.

Change the name properties of the command button to cmdRankStudents...then...go to events and on click and click on the right hand side of the blank white box and go into the code builder...

put in the following code:

Private Sub cmdRankStudents_Click()
On Error GoTo Err_cmdRankStudents_Click

DoCmd.SetWarnings False

'Opening ADODB connections and record sets
Dim con As ADODB.Connection

Dim rsStudents As ADODB.Recordset


Set con = CurrentProject.Connection

Set rsStudents = New ADODB.Recordset

Dim X As Integer
X = 1

Dim Y As Integer
Dim Z As Integer

rsStudents.MoveFirst
Y = rsStudents.Fields("StudentScore")
rsStudents.Fields("Ranking") = X
rsStudents.MoveNext
Do Until rsStudents.EOF

If rsStudent.Fields("StudentScore") = Y
rsStudents.AddNew
rsStudents.Fields("Ranking") = X
rsStudents.MoveNext
rsStudents.Update
Else
Y = rsStudents.Fields("StudentScore")
X = X + 1
rsStudents.AddNew
rsStudents.Fields("Ranking") = X
rsStudents.Update
rsStudents.MoveNext
EndIf

Loop

' if you want student ranking to skip if you have two rankings of 1 then go to 3, just use the Z variable and use it as a counter by adding under both possibilities of the if statement (Z = Z+1) and therefore X = X + Z under the second if statement would be 3 if there was a tie for 1

' now close everything up (connections and recordsets)

rsStudents.Close

Set con = Nothing

Set rsStudents = Nothing

DoCmd.SetWarnings True

Exit_cmdRankStudents_Click:
Exit Sub

Err_cmdRankStudents_Click:
MsgBox Err.Description
Resume Exit_cmdRankStudents_Click

End Sub


And I think that should work like a charm...let me know if you have any problems :)

Cheers
Kosmös

p.s. if you happen to teach at my school...Brandeis University...I better take your class and get that X=1 ranking :) lol
Dec 29 '06 #2
Kosmos
153 100+
to clarify...you should sort the field, studentgrades, in descending order...
If you are not familiar with access and don't know how to get to the onclick thing, you can just create this as a module and run the module to make sure it works...if it doesn't work let me know but if it does just look up DoCmd.RunModule and I'm sure there will be some place that will show you what to do from there.

I was new to access not too long ago... so I vividly remember what you're going through lol..... this, in fact, is the first time I've directly answered someone's question :)
Dec 29 '06 #3
NeoPa
32,556 Expert Mod 16PB
I am working on access database and need to give each student position based on their score in class.

For example:
A class with 5 students with the following scores:
Student Score
Student A: 32
Student B: 78
Student C: 90
Student D: 90
Student E: 21

I wish to generate their position thus:
Student Position in Class
Student A: 4
Student B: 2
Student C: 1
Student D: 1
Student E: 5

Take note of the tie between Student C and D please.

Thank you.
Assuming a table called [tblScore] with a [StudentID] field (numeric) and a [Score] field (numeric) then you would need something like this (NB the standard ordinal positioning system for exams is a count of the number of entries that are higher + 1) :
Expand|Select|Wrap|Line Numbers
  1. SELECT [StudentID],
  2.        [Score],
  3.        DCount('[Score]','[tblScore]','[Score]>' & [Score])+1 AS Position
  4. FROM tblScore
  5. ORDER BY DCount('[Score]','[tblScore]','[Score]>' & [Score])+1
Dec 30 '06 #4
NeoPa
32,556 Expert Mod 16PB
If other data (as yet untold) is required in the output then these can be linked in straightforwardly without complicating the query unduly.
Dec 30 '06 #5
Kosmos
153 100+
aww man and I did all that work for nothing lol..well except of course the learning experience :)
Jan 2 '07 #6
NeoPa
32,556 Expert Mod 16PB
aww man and I did all that work for nothing lol..well except of course the learning experience :)
Sorry Kosmos ;)
The learning experience is, after all, what we are all about here at TSDN though.
Jan 2 '07 #7
Thaks you all. I will try out your suggestions and get back with the results. This is my first time here and I am amazed how you have all gone to assist me with my problem. Thanks again.
Jan 2 '07 #8
Kosmos
153 100+
Sorry Kosmos ;)
The learning experience is, after all, what we are all about here at TSDN though.
:) indeed you are right....but given that I did not know that ranking system built into Outlook it seems I may have had a proper solution, as well :)
Jan 2 '07 #9
NeoPa
32,556 Expert Mod 16PB
I'm pleased we could help.
It was an interesting question :).
Jan 2 '07 #10
NeoPa
32,556 Expert Mod 16PB
:) indeed you are right....but given that I did not know that ranking system built into Outlook it seems I may have had a proper solution, as well :)
I'm not sure I follow you but I would certainly agree that your work was not wasted :) Good to see you posting as well - shows a good attitude.
Jan 2 '07 #11
Kosmos
153 100+
it has two integers...one that counts the amount of times the loop goes through but the other integer only changes if the grades from the previous are not equal and it changes by being set equal to the counting variable...therefore it covers the divide from 1 to 3 if there are two 1's for example (but you have to add the variable Z in for it to do this) otherwise it will just detect for 1 and 1 and then go to 2 which also may be a preferred system.

I never thought I'd get to the point where I'd be able to help but it turns out my previous work made me a valuable commodity...and it was this site that helped...and plus...I'm a musician and a politics and latin american studies major so of course I'm always willing to help out the community lol
Jan 2 '07 #12
NeoPa
32,556 Expert Mod 16PB
Cool Kosmos.
You'll be a senior member soon by the looks of things.
The more you help the more you learn; the more you learn the more you can help.
Good luck in your other studies too.

:)
Jan 2 '07 #13

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

Similar topics

3
by: Robi | last post by:
ok, I have a page, where the DOM is being updated by JavaScript. in the original version, there is a document.write creating the following: <div id="first"...
9
by: Omkar Singh | last post by:
I try to parse a XML document containg some references using XmlDocument Class' method GetElementbyTagName. It just give the content between starting tagName and ending tagName but not all...
2
by: sunny | last post by:
hello all, I am an Electrical background engineer n now trying to switch to software guy. I know basic knowledge of computers and now i am planning to take up the DB2 700 exam. I would...
162
by: techievasant | last post by:
hello everyone, Iam vasant from India.. I have a test+interview on C /C++ in the coming month so plz help me by giving some resources of FAQS, interview questions, tracky questions, multiple...
0
by: satan | last post by:
I need to call the recursive binarySearch method from my OrderedArrayList class into my main program public abstract class ArrayListClass { protected int length; //to store the...
5
by: Paul M | last post by:
Hi I need to create a map for a room (chairs, bed, TV, forniture, etc). All object allready exists like png images. I need to create a map for each room, i mean the user need to create. How...
2
by: Daniel Lipovetsky | last post by:
I would like for an object to "report" to a container object when a new instance is created or deleted. I could have a container object that is called when a new instance is created, as below. ...
0
by: shahiz | last post by:
This the error i get when i try to run my program Error: Unable to realize com.sun.media.amovie.AMController@18b81e3 Basically i have a mediapanel class that initialize and play the media as...
1
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.