M
Martin
Thank you for your help up front.
I have a qry that lists all student grades for a particular lesson. I am
trying to update this data based on a form where the instructor enters all
the student grades.
Here is my code:
Set myset = dbb.OpenRecordset("Student Grades", dbOpenTable)
Set qdf = db.QueryDefs("qryGradGrades")
qdf.Parameters(0) = [Forms]![frmSelectClass]![cboClassNum]
Set mysetstud = qdf.OpenRecordset
Stop
myset.Index = "grades" ' SSN, Class, Annex
Debug.Print iclass, sannex, sannex9, sSQLannex, sSQLannex9
If iclass < 10 Then
myset.Seek "=", mysetstud!SSN, Me.CLASS, sannex9
Else
myset.Seek "=", mysetstud!SSN, Me.CLASS, sannex
End If
'Stop
Do Until mysetstud.EOF
If myset.NoMatch Then
' Stop ' Add new record
myset.AddNew
myset![SSN] = iSSN
myset![Annex] = sannex
myset![CLASS] = iclass
myset![PX] = Me.PX
myset![WX] = Me.WX
'myset![QzWts] = Me.QW
myset![Wwts] = Me.WW
myset![Pwts] = Me.PW
myset![GrAvg] = Me.AGPA
myset![ovrall] = Me.OGPA
myset![RemedWX] = Me.chkW
myset.Update
Else ' If record already exists update for remediation only
myset.Edit
myset![SSN] = mysetstud!SSN
If iclass < 10 Then
myset![Annex] = sannex9
Else
myset![Annex] = sannex
End If
myset![CLASS] = [Forms]![frmSelectClass].[cboClassNum]
'*********************************
' these following lines are giving me the error
myset![PX] = mysetstud.['" & sSQLannex9 & iclass & "'PX]
myset![WX] = mysetstud.['" & sSQLannex9 & iclass & "'WX]
myset![Wwts] = mysetstud.['" & sSQLannex9 & iclass & "'WW]
myset![Pwts] = mysetstud.['" & sSQLannex9 & iclass & "'PW]
myset![GrAvg] = mysetstud.['" & sSQLannex9 & iclass & "'AGPA]
myset![ovrall] = mysetstud.['" & sSQLannex9 & iclass & "'OGPA]
myset![RemedWX] = mysetstud.['" & sSQLannex9 & iclass & "'chkW]
'************************************************
myset.Update
End If
mysetstud.MoveNext
If mysetstud.EOF Then
Exit Do
End If
Loop
Table student grades has SSN and then GD-01 grades, GD-02 grades, GD-03
grades etc.
I have code that uses an append SQL statement and it works just fine except
that it creates duplicate records. I want to add a new record if one does
not exist or update the record if one already exists. That is why I am going
down this road.
Thank you again for any help you can provide.
I have a qry that lists all student grades for a particular lesson. I am
trying to update this data based on a form where the instructor enters all
the student grades.
Here is my code:
Set myset = dbb.OpenRecordset("Student Grades", dbOpenTable)
Set qdf = db.QueryDefs("qryGradGrades")
qdf.Parameters(0) = [Forms]![frmSelectClass]![cboClassNum]
Set mysetstud = qdf.OpenRecordset
Stop
myset.Index = "grades" ' SSN, Class, Annex
Debug.Print iclass, sannex, sannex9, sSQLannex, sSQLannex9
If iclass < 10 Then
myset.Seek "=", mysetstud!SSN, Me.CLASS, sannex9
Else
myset.Seek "=", mysetstud!SSN, Me.CLASS, sannex
End If
'Stop
Do Until mysetstud.EOF
If myset.NoMatch Then
' Stop ' Add new record
myset.AddNew
myset![SSN] = iSSN
myset![Annex] = sannex
myset![CLASS] = iclass
myset![PX] = Me.PX
myset![WX] = Me.WX
'myset![QzWts] = Me.QW
myset![Wwts] = Me.WW
myset![Pwts] = Me.PW
myset![GrAvg] = Me.AGPA
myset![ovrall] = Me.OGPA
myset![RemedWX] = Me.chkW
myset.Update
Else ' If record already exists update for remediation only
myset.Edit
myset![SSN] = mysetstud!SSN
If iclass < 10 Then
myset![Annex] = sannex9
Else
myset![Annex] = sannex
End If
myset![CLASS] = [Forms]![frmSelectClass].[cboClassNum]
'*********************************
' these following lines are giving me the error
myset![PX] = mysetstud.['" & sSQLannex9 & iclass & "'PX]
myset![WX] = mysetstud.['" & sSQLannex9 & iclass & "'WX]
myset![Wwts] = mysetstud.['" & sSQLannex9 & iclass & "'WW]
myset![Pwts] = mysetstud.['" & sSQLannex9 & iclass & "'PW]
myset![GrAvg] = mysetstud.['" & sSQLannex9 & iclass & "'AGPA]
myset![ovrall] = mysetstud.['" & sSQLannex9 & iclass & "'OGPA]
myset![RemedWX] = mysetstud.['" & sSQLannex9 & iclass & "'chkW]
'************************************************
myset.Update
End If
mysetstud.MoveNext
If mysetstud.EOF Then
Exit Do
End If
Loop
Table student grades has SSN and then GD-01 grades, GD-02 grades, GD-03
grades etc.
I have code that uses an append SQL statement and it works just fine except
that it creates duplicate records. I want to add a new record if one does
not exist or update the record if one already exists. That is why I am going
down this road.
Thank you again for any help you can provide.