adhoustonj
Member
- Local time
- Yesterday, 22:56
- Joined
- Sep 23, 2022
- Messages
- 192
Hello AWF,
I have just migrated a back end access db to sql server, and have been altering code to include the dbOpenDynaset & dbSeeChanges as I was getting error messages about needing dbSeeChanges when interacting with IDENTITY columns in sql server.
The below function is called in a procedure with a form load event, and I'm getting the 3027 error about read only, cannot update when it is editing the recordset. All tables have primary keys, which seemed to solve for other threads I've read. Can I still use this code or am I missing anything obvious?
Thanks
I have just migrated a back end access db to sql server, and have been altering code to include the dbOpenDynaset & dbSeeChanges as I was getting error messages about needing dbSeeChanges when interacting with IDENTITY columns in sql server.
The below function is called in a procedure with a form load event, and I'm getting the 3027 error about read only, cannot update when it is editing the recordset. All tables have primary keys, which seemed to solve for other threads I've read. Can I still use this code or am I missing anything obvious?
Thanks
Code:
Function sort_time_color(pcd As LongPtr)
Dim newseq As LongPtr, side As LongPtr, tasksec As LongPtr, sta As LongPtr, newst_seq As LongPtr
Dim newv As String
Dim stc As Integer
Set db = CurrentDb()
'resequence the pcd seq numbers
strSQL = "SELECT tblTask.seq, tblTask.st_seq, tblTask.task_id, tblTask.stat_id, tblTask.stat_color " _
& "FROM (tblSide INNER JOIN tblZone ON tblSide.side_id = tblZone.side_id) INNER JOIN ((tblStation INNER JOIN tblPCDzone ON tblStation.zone_id = tblPCDzone.zone_id) INNER JOIN tblTask ON (tblTask.pcd_id = tblPCDzone.pcd_id) AND (tblStation.stat_id = tblTask.stat_id)) ON (tblZone.zone_id = tblStation.zone_id) AND (tblZone.zone_id = tblPCDzone.zone_id) " _
& "WHERE (((tblPCDzone.pcd_id) = " & pcd & ")) " _
& "ORDER BY tblSide.side_id, tblStation.sec, tblTask.position, tblTask.seq, IIf([seq1] Is Null,0,[seq1]) DESC , tblTask.seq2 DESC"
'Debug.Print strSQL
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
If rs.RecordCount > 0 Then
rs.MoveFirst
newseq = 1
newst_seq = 1
stc = 1
sta = rs!stat_id
While Not rs.EOF
If IsNull(rs!seq) Or rs!seq <> newseq Then
rs.Edit
rs!seq = newseq
rs.Update
End If
If IsNull(rs!stat_id) Or rs!stat_id <> sta Then
newst_seq = 1
If stc = 1 Then
rs.Edit
rs!stat_color = 2
rs.Update
stc = 2
Else
rs.Edit
rs!stat_color = 1
rs.Update
stc = 1
End If
Else
'ERROR is on next line "rs.Edit"
rs.Edit
rs!stat_color = stc
rs.Update
End If
If IsNull(rs!st_seq) Or rs!st_seq <> newst_seq Then
rs.Edit
rs!st_seq = newst_seq
rs.Update
End If
newseq = newseq + 1
newst_seq = newst_seq + 1
sta = rs!stat_id
rs.MoveNext
Wend
strSQL = "DELETE ltblTemp_secs.* FROM ltblTemp_secs"
db.Execute strSQL
'task secs
strSQL = "UPDATE tblTask LEFT JOIN tblTask_times ON (tblTask.task_id = tblTask_times.task_id) AND (tblTask.task_id = tblTask_times.task_id) SET tblTask.task_secs = 0 " _
& "WHERE (((tblTask.task_secs)>0) AND ((tblTask_times.task_id) Is Null) and ((tblTask.pcd_id)=" & pcd & "))"
db.Execute strSQL
strSQL = "INSERT INTO ltblTemp_secs ( tid, secs ) " _
& "SELECT qryTask_secs.task_id, qryTask_secs.task_sec " _
& "FROM qryTask_secs INNER JOIN tblTask ON qryTask_secs.task_id = tblTask.task_id " _
& "WHERE (((tblTask.pcd_id)=" & pcd & "))"
db.Execute strSQL
strSQL = "UPDATE tblTask INNER JOIN ltblTemp_secs ON tblTask.task_id = ltblTemp_secs.tid SET tblTask.task_secs = [ltblTemp_secs]![secs];"
db.Execute strSQL
strSQL = "DELETE ltblTemp_secs.* FROM ltblTemp_secs"
db.Execute strSQL
'station secs
strSQL = "INSERT INTO ltblTemp_secs ( tid, secs ) " _
& "SELECT qryStation_secs.stat_id, qryStation_secs.stat_sec " _
& "FROM qryStation_secs " _
& "WHERE (((qryStation_secs.pcd_id)=" & pcd & "));"
db.Execute strSQL
strSQL = "UPDATE tblTask INNER JOIN ltblTemp_secs ON tblTask.stat_id = ltblTemp_secs.tid SET tblTask.stat_secs = [ltblTemp_secs]![secs];"
db.Execute strSQL
strSQL = "DELETE ltblTemp_secs.* FROM ltblTemp_secs"
db.Execute strSQL
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Function