Hi
I am now trying to find the last record in a table and update a field in that table. The code I have is
Dim dbsCollege As DAO.Database
Dim rstStudentAnnualcourses As DAO.Recordset
Dim strSQL As String
Dim intLastRecord As Integer
Set dbsCollege = CurrentDb
Set rstStudentAnnualcourses = dbsCollege.OpenRecordset("tblStudentsAnnualCourses")
strSQL = "Update rstStudentsAnnualcourses" & _
"Set StuAnnCrsesCrseID = ' & intCrseID & '" & _
"WHERE StuAnnCrsesID = ' & intLastRecord & '"
DoCmd.SetWarnings False
rstStudentAnnualcourses.MoveLast
intLastRecord = StuAnnCrsesID
DoCmd.RunSQL strSQL
intCrseID is a public variable that I created and should be an integer ID from a previous action. I get a syntax error in the update statement? Can anybody help?
Regards
Paul
Salisbury, UK
I am now trying to find the last record in a table and update a field in that table. The code I have is
Dim dbsCollege As DAO.Database
Dim rstStudentAnnualcourses As DAO.Recordset
Dim strSQL As String
Dim intLastRecord As Integer
Set dbsCollege = CurrentDb
Set rstStudentAnnualcourses = dbsCollege.OpenRecordset("tblStudentsAnnualCourses")
strSQL = "Update rstStudentsAnnualcourses" & _
"Set StuAnnCrsesCrseID = ' & intCrseID & '" & _
"WHERE StuAnnCrsesID = ' & intLastRecord & '"
DoCmd.SetWarnings False
rstStudentAnnualcourses.MoveLast
intLastRecord = StuAnnCrsesID
DoCmd.RunSQL strSQL
intCrseID is a public variable that I created and should be an integer ID from a previous action. I get a syntax error in the update statement? Can anybody help?
Regards
Paul
Salisbury, UK