gpt4 book ai didi

ms-access - 遍历表和更改值时 Access 崩溃

转载 作者:行者123 更新时间:2023-12-03 17:22:46 27 4
gpt4 key购买 nike

当我遍历表并使用以下代码更改字段之一的值时,Access不断崩溃:

Set db = CurrentDb
Set rs = db.OpenRecordset(prProdTblName)
'PrevDept , PrevOpNo, PrevPartNo
rs.MoveFirst
rs.Edit
rs![Op No] = 10
rs.Update
Do Until rs.EOF
With rs
PrevOpNo = ![Op No]
PrevDept = ![Department Code]
PrevPartNo = ![Part No]
.MoveNext
.Edit
If (![Department Code] = "SMD" And PrevDept <> "SMD") Then
![Op No] = 500
ElseIf (![Department Code] <> "SMD" And PrevDept = "SMD" And ![Part No] = PrevPartNo) Then
![Op No] = 1000
ElseIf (rs![Part No] <> PrevPartNo) Then
![Op No] = 10
Else
![Op No] = PrevOpNo + 10
End If
.Update
End With
Loop
rs.Close
Set rs = Nothing

另外,当我尝试使用备用SQL代码时,这似乎是一个无休止的查询:
SQLcommandStr = "SELECT T1.[ID], (Select IIF((T1.[Department Code]='SMD') AND (T2.[Department Code]<>'SMD'),500,IIF((T1.[Department Code]<>'SMD') AND (T2.[Department Code]='SMD') AND (T1.[Part No] = T2.[Part No]),1000,IIF((T1.[Part No] <> T2.[Part No] OR (T1.[ID] = (SELECT MIN(T4.[ID]) FROM " & prProdTblName & " T4))),10,T2.[Op No] + 10))) From " & prProdTblName & " T2 WHERE T2.[ID] = (SELECT MAX(T3.[ID]) FROM " & prProdTblName & " T3 WHERE T1.[ID] > T3.[ID])) INTO TblTemp FROM " & prProdTblName & " T1"

DoCmd.RunSQL SQLcommandStr

最佳答案

您可能在EOF反弹:

Set db = CurrentDb
Set rs = db.OpenRecordset(prProdTblName)
rs.MoveFirst
rs.Edit
rs![Op No] = 10
rs.Update
Do Until rs.EOF
With rs
PrevOpNo = ![Op No]
PrevDept = ![Department Code]
PrevPartNo = ![Part No]
.MoveNext
If .EOF = False Then
.Edit
If (![Department Code] = "SMD" And PrevDept <> "SMD") Then
![Op No] = 500
ElseIf (![Department Code] <> "SMD" And PrevDept = "SMD" And ![Part No] = PrevPartNo) Then
![Op No] = 1000
ElseIf (rs![Part No] <> PrevPartNo) Then
![Op No] = 10
Else
![Op No] = PrevOpNo + 10
End If
.Update
End If
End With
Loop
rs.Close
Set rs = Nothing

关于ms-access - 遍历表和更改值时 Access 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29728015/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com