HI,
I am using the following function to delete a record from sysDeptDef table which is not present in ups_new table. I have two rows for the same deptid but diff attid. when i use the delete command the two rows get deleted but when the loop executes it cannot find the deptid so it fails.can please anyone suggest me how to handle this situation.
Dim CurrentLevel As Integer
Dim CurrentDeptId As Variant
Dim LevelUp1 As String
Dim LevelUp2 As String
Dim LobId As String
Dim AttId As Integer
Dim Oc_Id As Integer
Dim LevelCheck As Boolean
Set rst_local = dbs.OpenRecordset("SELECT * FROM sysDeptDef")
Do Until rst_local.EOF
[COLOR=red yellow]CurrentDeptId = rst_local("DeptId") (Error record not found)[/color]
CurrentLevel = rst_local("DeptLevel")
LevelUp1 = "L" & CurrentLevel - 1 & "_DEPTID"
LevelUp2 = "L" & CurrentLevel - 2 & "_DEPTID"
Set rst_pplops = dbs.OpenRecordset("SELECT " & LevelUp1 & "," & LevelUp2 & ",Dept_Level,EFF_STATUS,DeptId FROM ups_new WHERE DEPTID = '" & CurrentDeptId & "'")
If rst_pplops.RecordCount <> 0 Then
If rst_pplops(LevelUp1) = rst_local("DeptId_Up1") And _
rst_pplops(LevelUp2) = rst_local("DeptId_Up2") And _
rst_pplops("Dept_Level") = CurrentLevel And rst_pplops("EFF_STATUS") = "A" And rst_pplops("DeptId") = CurrentDeptId Then
rst_local.Edit
rst_local("LevelCheck") = True
rst_local.Update
End If
Else
Set rst_check = dbs.OpenRecordset("select Deptid,AttId from sysDeptDef where Deptid='" & CurrentDeptId & "'")
If rst_check.RecordCount > 0 Then
MsgBox "Deptid '" & CurrentDeptId & "' to be deleted since record not found in pplops and "
[COLOR=red yellow]dbs.Execute ("delete AttId from sysDeptDef where DeptId='" & CurrentDeptId & "'")[/color]
End If
End If
rst_pplops.Close
rst_local.MoveNext
End If
Loop
rst_local.Close
Thanks for your reply
I am using the following function to delete a record from sysDeptDef table which is not present in ups_new table. I have two rows for the same deptid but diff attid. when i use the delete command the two rows get deleted but when the loop executes it cannot find the deptid so it fails.can please anyone suggest me how to handle this situation.
Dim CurrentLevel As Integer
Dim CurrentDeptId As Variant
Dim LevelUp1 As String
Dim LevelUp2 As String
Dim LobId As String
Dim AttId As Integer
Dim Oc_Id As Integer
Dim LevelCheck As Boolean
Set rst_local = dbs.OpenRecordset("SELECT * FROM sysDeptDef")
Do Until rst_local.EOF
[COLOR=red yellow]CurrentDeptId = rst_local("DeptId") (Error record not found)[/color]
CurrentLevel = rst_local("DeptLevel")
LevelUp1 = "L" & CurrentLevel - 1 & "_DEPTID"
LevelUp2 = "L" & CurrentLevel - 2 & "_DEPTID"
Set rst_pplops = dbs.OpenRecordset("SELECT " & LevelUp1 & "," & LevelUp2 & ",Dept_Level,EFF_STATUS,DeptId FROM ups_new WHERE DEPTID = '" & CurrentDeptId & "'")
If rst_pplops.RecordCount <> 0 Then
If rst_pplops(LevelUp1) = rst_local("DeptId_Up1") And _
rst_pplops(LevelUp2) = rst_local("DeptId_Up2") And _
rst_pplops("Dept_Level") = CurrentLevel And rst_pplops("EFF_STATUS") = "A" And rst_pplops("DeptId") = CurrentDeptId Then
rst_local.Edit
rst_local("LevelCheck") = True
rst_local.Update
End If
Else
Set rst_check = dbs.OpenRecordset("select Deptid,AttId from sysDeptDef where Deptid='" & CurrentDeptId & "'")
If rst_check.RecordCount > 0 Then
MsgBox "Deptid '" & CurrentDeptId & "' to be deleted since record not found in pplops and "
[COLOR=red yellow]dbs.Execute ("delete AttId from sysDeptDef where DeptId='" & CurrentDeptId & "'")[/color]
End If
End If
rst_pplops.Close
rst_local.MoveNext
End If
Loop
rst_local.Close
Thanks for your reply