I'm having some trouble with the code on this form - it's intended to increment the grades of all the students in the database.
If I open the form in design view and then switch to normal view it runs fine. If I double click it directly, however, it throws this error:
Runtime Error '2046'
The command or action 'GoToRecord' isn't available now.
When I debug the main loop in the code has always worked fine a few times before crashing.
The crash occurs on line 11.
Can anyone throw any light on the situation?
If I open the form in design view and then switch to normal view it runs fine. If I double click it directly, however, it throws this error:
Runtime Error '2046'
The command or action 'GoToRecord' isn't available now.
When I debug the main loop in the code has always worked fine a few times before crashing.
The crash occurs on line 11.
Can anyone throw any light on the situation?
Code:
Private Sub Form_Open(Cancel As Integer)
'Ups the grades of all students
'count records
Dim recordCount As Integer
recordCount = DCount("[ID]", "tblStudents")
DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, 1
For a = 1 To recordCount
DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, a
If Form_frmGradeUpdater.chkAlumni.Value = "0" Then GradeUp
Next a
Form_frmKeyData.flgUpdated = -1
DoCmd.Close
End Sub
Private Function GradeUp()
Dim maxGrade As Integer
maxGrade = Form_frmKeyData.cmbHighestGrade.Value
Dim response As String 'for alumni question
'check if the grade value is null, and throw up a warning message if so.
If (IsNull(Form_frmGradeUpdater.Grade.Value)) Then
MsgBox ("No grade data for: " & Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
Exit Function
End If
Dim currentGrade As String
currentGrade = Form_frmGradeUpdater.Grade.Value
Dim nameStore As String
nameStore = (Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
If currentGrade = "Grade 8" Then
If maxGrade = 8 Then
response = MsgBox("Should " & nameStore & " become an alumni student?", vbYesNo)
If response = 6 Then Form_frmGradeUpdater.chkAlumni = -1
End If
currentGrade = "Grade 9"
End If
If currentGrade = "Grade 7" Then currentGrade = "Grade 8"
If currentGrade = "Grade 6" Then currentGrade = "Grade 7"
If currentGrade = "Grade 5" Then currentGrade = "Grade 6"
If currentGrade = "Grade 4" Then currentGrade = "Grade 5"
If currentGrade = "Grade 3" Then currentGrade = "Grade 4"
If currentGrade = "Grade 2" Then currentGrade = "Grade 3"
If currentGrade = "Grade 1" Then currentGrade = "Grade 2"
If currentGrade = "Kindergarten" Then currentGrade = "Grade 1"
If currentGrade = "Preschool" Then currentGrade = "Kindergarten"
Form_frmGradeUpdater.Grade.Value = currentGrade
Exit Function
End Function
Comment