View Full Version : Changing a field Value


RACHNA
01-06-2000, 10:09 AM
I have a combo box field on my form for Grade Level (1-5). I'm looking for a way to advance all students to the next grade.

4th Graders->5th Graders
3rd Graders->4th Graders
2nd Graders->3rd Graders
1st Graders-> 2nd Graders

Any suggestions would be helpful

Travis
01-06-2000, 11:07 PM
If you are using just the numbers 1 - 5 to represent the grade you can easily use an update Query similar to this:

--------------------------------------
stSQL = "UPDATE [Table1] SET [Table1].[Grade] = [Grade]+1;"
currentdb.execute stSQL
--------------------------------------

But if you are using a String Value such as 4th Graders it will need to be a little different. I recommed this approach as it will loop through the records once and make the changes you require:

---------------------------------
Dim stSQL as String
Dim rst as recordset

stSQL = "Select * From Table1"
Set rst = Currentdb.OpenRecordset(stSQL)
rst.moveFirst

With rst
do while Not .EOF
.Edit
Select case .Fields("Grades")
Case "5th Graders"
![Grades]= "6th Graders"
Case "4th Graders"
![Grades]= "5th Graders"
Case "3rd Graders"
![Grades]= "4th Graders"
Case "2nd Graders"
![Grades]= "3rd Graders"
Case "1st Graders"
![Grades]= "2nd Graders"
End Select
.MoveNext
loop
End with
--------------------------------