我有一个On_Load()
子程序,用于检查子表单上的记录,按记录记录。例如,如果子窗体加载了12条记录,我需要从第一条记录开始,运行DCount
(它检查作业号是否出现在不同的表中),然后移动到下一个记录,并检查一个等,直到它到达最后一个记录。这是我目前的代码:
Set rst = Me.RecordsetClone
On Error Resume Next
rst.MoveFirst
'Put code to check keyword schedule here. First get job no
Do Until Me.Specific_Job_No.Value = "00"
strSpec = Format(Me.Specific_Job_No.Value, "00")
strJob = Left(Me.Parent.JobRef.Value, 18) + strSpec
'Then check if that job no is in slot 1, then 2, etc
If DCount("*", "tblKeywordsSchedule", "[Slot1] Like ""*" & strJob & "*""") > 0 Then
Me![Added to Schedule] = True
Me![Added to Schedule].Locked = True
Else
Me![Added to Schedule] = False
Me![Added to Schedule].Locked = False
End If
'Then go to next record
rst.MoveNext
Loop
我的问题是,它卡在rst.MoveNext
上,并且一遍又一遍地检查第一条记录。我做错了什么?
答案 0 :(得分:0)
您的问题是您无法为每条记录单独锁定字段。
因此{{1}}可能会在循环期间更改其锁定,但会保留循环中最后一条记录的设置。
答案 1 :(得分:0)
我现在已经把它整理出来了。在此页面上找到TheSmileyCoder的答案: https://bytes.com/topic/access/answers/942501-looping-through-subform-records
我指的是一个表单控件(我!)而不是记录集克隆来更新strSpec和strJob字符串 - 这就是我需要知道的。
If rst.RecordCount > 0 Then
With rst
rst.MoveFirst
Do While Not .EOF
strSpec = Format(rst![Specific Job No], "00")
strJob = Left(Me.Parent.JobRef.Value, 18) + strSpec
'Then check if that job no is in slot 1, then 2, etc
If DCount("*", "tblKeywordsSchedule", "[Slot1] Like ""*" & strJob & "*""") > 0 Then
.Edit
rst![Added to Schedule] = True
.Update
Else
.Edit
rst![Added to Schedule] = False
.Update
End If
.MoveNext
Loop
End With
End If