VBA 记录集更新挂在特定记录上
VBA Recordset Update Hanging On Specfic Record
所以我有以下...
Sub test4()
Dim db As DAO.Database
Dim Source_rst As DAO.Recordset
Dim Dest_rst As DAO.Recordset
Set db = CurrentDb
Set Source_rst = db.OpenRecordset("SELECT DISTINCTROW [Scorecard Last Ran].[Scorecard ID], Round(([DQS - Scorecard History].[No Passed]/([DQS - Scorecard History].[No Passed]+[DQS - Scorecard History].[No Failed]))*100,1) & '%' AS Score FROM [DQS - Scorecards] INNER JOIN ((SELECT [DQS - Scorecard History].[Scorecard ID], Max([DQS - Scorecard History].[Date/Time Scorecard Ran]) AS [MaxOfDate/Time Scorecard Ran] FROM [DQS - Scorecard History] GROUP BY [DQS - Scorecard History].[Scorecard ID]) AS [Scorecard Last Ran] INNER JOIN [DQS - Scorecard History] ON ([Scorecard Last Ran].[MaxOfDate/Time Scorecard Ran] = [DQS - Scorecard History].[Date/Time Scorecard Ran]) AND ([Scorecard Last Ran].[Scorecard ID] = [DQS - Scorecard History].[Scorecard ID])) ON [DQS - Scorecards].ID = [DQS - Scorecard History].[Scorecard ID];")
Set Dest_rst = db.OpenRecordset("DQS - Scorecards")
If (Source_rst.BOF And Source_rst.EOF) Or (Dest_rst.BOF And Dest_rst.EOF) Then Exit Sub
While (Not Source_rst.EOF)
Dest_rst.MoveFirst
While (Not Dest_rst.EOF)
If Dest_rst![ID] = Source_rst![Scorecard ID] And Dest_rst![ID] <> 3 Then
Debug.Print Source_rst![Scorecard ID] & " - " & Source_rst![Score]
Dest_rst.Edit
Dest_rst![Score] = Source_rst![Score]
Dest_rst.Update
DoEvents
End If
Dest_rst.MoveNext
Wend
Source_rst.MoveNext
Wend
End Sub
很简单吧?除非我删除它挂起的 Dest_rst![ID] <> 3
,即使我离开它几个小时。记录 3 没有什么特别之处,进入的数据是相同的,一个格式化为字符串的百分比。如果我排除这条记录,效果很好。
我知道更新查询会更有效,但它也挂起。有什么我想念的吗?!
Dest_rst 是一个非常小的 SharePoint 列表。
原来我的 SharePoint 列表只是个屁。从我的数据库中完全删除列表,重新添加它,一切都很好,恢复了理智!
所以我有以下...
Sub test4()
Dim db As DAO.Database
Dim Source_rst As DAO.Recordset
Dim Dest_rst As DAO.Recordset
Set db = CurrentDb
Set Source_rst = db.OpenRecordset("SELECT DISTINCTROW [Scorecard Last Ran].[Scorecard ID], Round(([DQS - Scorecard History].[No Passed]/([DQS - Scorecard History].[No Passed]+[DQS - Scorecard History].[No Failed]))*100,1) & '%' AS Score FROM [DQS - Scorecards] INNER JOIN ((SELECT [DQS - Scorecard History].[Scorecard ID], Max([DQS - Scorecard History].[Date/Time Scorecard Ran]) AS [MaxOfDate/Time Scorecard Ran] FROM [DQS - Scorecard History] GROUP BY [DQS - Scorecard History].[Scorecard ID]) AS [Scorecard Last Ran] INNER JOIN [DQS - Scorecard History] ON ([Scorecard Last Ran].[MaxOfDate/Time Scorecard Ran] = [DQS - Scorecard History].[Date/Time Scorecard Ran]) AND ([Scorecard Last Ran].[Scorecard ID] = [DQS - Scorecard History].[Scorecard ID])) ON [DQS - Scorecards].ID = [DQS - Scorecard History].[Scorecard ID];")
Set Dest_rst = db.OpenRecordset("DQS - Scorecards")
If (Source_rst.BOF And Source_rst.EOF) Or (Dest_rst.BOF And Dest_rst.EOF) Then Exit Sub
While (Not Source_rst.EOF)
Dest_rst.MoveFirst
While (Not Dest_rst.EOF)
If Dest_rst![ID] = Source_rst![Scorecard ID] And Dest_rst![ID] <> 3 Then
Debug.Print Source_rst![Scorecard ID] & " - " & Source_rst![Score]
Dest_rst.Edit
Dest_rst![Score] = Source_rst![Score]
Dest_rst.Update
DoEvents
End If
Dest_rst.MoveNext
Wend
Source_rst.MoveNext
Wend
End Sub
很简单吧?除非我删除它挂起的 Dest_rst![ID] <> 3
,即使我离开它几个小时。记录 3 没有什么特别之处,进入的数据是相同的,一个格式化为字符串的百分比。如果我排除这条记录,效果很好。
我知道更新查询会更有效,但它也挂起。有什么我想念的吗?!
Dest_rst 是一个非常小的 SharePoint 列表。
原来我的 SharePoint 列表只是个屁。从我的数据库中完全删除列表,重新添加它,一切都很好,恢复了理智!