How to count existing records where StudentID = ThisStudent

W

wdsnews

I'm trying to count the number of classes a student has in their "Student
Schedule" table as we enter more records for that student. Assuming the
records are entered in the order of the student's preference, then we can
set the "Preference" field to be equal to the number of records. But I'm
new to Access and it doesn't behave as I expect. I get runtime error
'2001', "You cancelled the previous operation". Perhaps I need some kind of
post or 'save record' command?

I've attached the following code to the event called AfterUpdate of a field
called [CourseNo] on a subform called sbfSchedule. The sbfSchedule is
nested in the People form. The error occurs between the two msgBox
commands. After I get past this error, the next goal is to assign
intClassCount to the [Preference] field.

Private Sub cboCourseNo_AfterUpdate()
Dim intClassCount As Integer
Dim strTemp As String
strTemp = MsgBox("Box1", vbInformation, "no message")

intClassCount = DCount("[Student ID]", "[Student Schedule]", "[Student ID]
= Form!People!ID")
strTemp = MsgBox("Here's the ClassCount " & intClassCount, vbInformation,
"intClassCount")
End Sub

The sbfSchedule is based on a table called [Student Schedule] with fields
called [ID], [Student ID], [Course ID], [Confirmed], [Preference].

thanks for your help. I'm learning fast.
 
K

Ken Snell \(MVP\)

Move the parameter outside the " string:

intClassCount = DCount("[Student ID]", "[Student Schedule]", "[Student ID]
=" & Forms!People!ID)


And, assuming that this code is running in the People form:

intClassCount = DCount("[Student ID]", "[Student Schedule]", "[Student ID]
=" & Me.ID.Value)
 
W

wdsnews

Thank you Ken. I don't understand it, but do doubt I'll be paying close
attention when I get to that part of the book. I appreciate your help.


Ken Snell (MVP) said:
Move the parameter outside the " string:

intClassCount = DCount("[Student ID]", "[Student Schedule]", "[Student
ID] =" & Forms!People!ID)


And, assuming that this code is running in the People form:

intClassCount = DCount("[Student ID]", "[Student Schedule]", "[Student
ID] =" & Me.ID.Value)

--

Ken Snell
<MS ACCESS MVP>



wdsnews said:
I'm trying to count the number of classes a student has in their "Student
Schedule" table as we enter more records for that student. Assuming the
records are entered in the order of the student's preference, then we can
set the "Preference" field to be equal to the number of records. But I'm
new to Access and it doesn't behave as I expect. I get runtime error
'2001', "You cancelled the previous operation". Perhaps I need some kind
of post or 'save record' command?

I've attached the following code to the event called AfterUpdate of a
field called [CourseNo] on a subform called sbfSchedule. The sbfSchedule
is nested in the People form. The error occurs between the two msgBox
commands. After I get past this error, the next goal is to assign
intClassCount to the [Preference] field.

Private Sub cboCourseNo_AfterUpdate()
Dim intClassCount As Integer
Dim strTemp As String
strTemp = MsgBox("Box1", vbInformation, "no message")

intClassCount = DCount("[Student ID]", "[Student Schedule]", "[Student
ID] = Form!People!ID")
strTemp = MsgBox("Here's the ClassCount " & intClassCount,
vbInformation, "intClassCount")
End Sub

The sbfSchedule is based on a table called [Student Schedule] with fields
called [ID], [Student ID], [Course ID], [Confirmed], [Preference].

thanks for your help. I'm learning fast.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top