I am not good in programming but i have a passion for it. I am creating a Exam Grading system in VB 6.0 with MS Access as back end.
I have a problem here:
I have 2 tables in MS Access (tblGrades and tmpGrades) with fields StdRegno, Term, ExamType, AvgScore, AvgGrade. I would like to extract the positions using AvgScore but i don't know how to handle a tie (Where students have same average score) such that after say two students in number 2 tie, then the next number will be Position 4 (i.e 1, 2, 2, 4, 5, 6, 7). I hope this makes sense.
So far i have done the following and i am finding it clumsy:
Private Sub Command2_Click()
Dim dbs As ADODB.Connection
Set dbs = New ADODB.Connection
dbs.Open "Provider=Microsoft.jet.OLEDB.4.0;Data source=C:\Sgs\Sgs.mdb"
' Select all records in the New Customers table
' and add them to the Customers table.
dbs.Execute " INSERT INTO tmpGrades " _
& "SELECT StdRegno, Term, ExamType, AvgScore, AvgGrade " _
& "FROM tblGrades " _
& "ORDER BY AvgScore " _
& "DESC", , adExecuteNoRecords
dbs.Close
Set dbs = Nothing
Call UpdatePositions ' Calling the UpdatePositions Procedure
End Sub
Sub UpdatePositions()
Connection
Dim rs As New ADODB.Recordset
Dim Pos As Integer
Set rs = New ADODB.Recordset
With rs
.Open "SELECT * FROM tmpGrades ORDER by AvgScore DESC", cn, 2, 3
Pos = 0 'Initialize the position with position number 1
Do While Not .EOF
Pos = Pos + 1 ' increment the position
'Is there a way i can check if the AvgScore is the same and I don't increment Position ranking???
!Position = Pos ' update the position field
.MoveNext
Loop
End With
MsgBox "Positions Updated...", , "updates"
Set rs = Nothing
End Sub
Thank you good people!!
I would appreciate a more cleaner leaner code with an example.
Enough Respect to you all.
Simon
- Add new comment
- 134 views