Recordsetclone不在Subform上工作

时间:2015-11-03 13:02:48

标签: ms-access access-vba ms-access-2010 recordset subform

我在调整这段代码时遇到了问题,因为我的子窗体中的记录已经过循环调整。当子窗体加载时,它循环遍历当前过滤的记录,根据其在另一个表(tDPARSHEET)中的状态相应状态调整字段6。但是,当我从主窗体上的刷新按钮调用它时,我无法使其工作

With Me.RecordsetClone
If Not (.BOF And .EOF) Then
.MoveFirst
While Not .EOF
Debug.Print .Fields(6).Name, .Fields(6).Value
If .Fields(6).Value <> DLookup("OverallStatus", "tDPARSHEET", "[LocalPartNumber]='" & .Fields(3).Value & "' AND [LocalRevision]='" & .Fields(4).Value & "'") Then
'Debug.Print "No Match"
.Edit
.Fields(6).Value = DLookup("OverallStatus", "tDPARSHEET", "[LocalPartNumber]='" & .Fields(3).Value & "' AND [LocalRevision]='" & .Fields(4).Value & "'")
.Update
Else
'Debug.Print "!!Match Found!!"
End If
.MoveNext
Wend
.Requery
End If
End With

我相信这是因为Me.Recordsetclone在子窗体加载时被调用,如果我想从mainform调用它,特别是从我用来刷新主窗体的按钮,那么我需要直接叫出来

Forms!frmMain.frmsub.Form.recordsetclone是我一直看到的语法。除了我在网络上看到的任何其他语法[me.frmsub.form.recorsetclone // frmMain.subfrmctrlname.form.recordsetclone // me.frmMain.frmsub.forms.subfrmctrlname.recorsetclone]其中一些似乎只是看起来错了,但我尝试了它们。我在下面提供了一些表单信息,用于语法

Mainform:frmDPARTOP
SubForm表格名称:frmDPARPARTSSubform
SubForm Ctl名称:subDPARTOP

我做错了什么,不允许我让这个记录集工作,目前我有Me.subDPARTOP.Form.RecordsetClone,我没有收到错误,它只是没有工作< / p>

以下是我按照此处的说明操作的当前代码。据我所知,当前代码没有达到第5行的Debug.Print,因为立即窗口中没有显示任何内容

Private Sub Command31_Click()
'Loops through Subform and updates DPAR Status from tDPARSHEET
'Main Form Name is frmDPARTOP
'Sub Form Name is frmDPARPARTSSubform
'Sub Form Control is subDPARTOP
Dim Field6 As Variant
With Me!subDPARTOP.Form.RecordsetClone
While Not .EOF
    Field6 = DLookup("OverallStatus", "tDPARSHEET", "[LocalCustomer]='" & .Fields(2).Value & "' AND [LocalPartNumber]='" & .Fields(3).Value & "' AND [LocalRevision]='" & .Fields(4).Value & "'")
    Debug.Print .Fields(6).Name, .Fields(6).Value, Field6
    If .Fields(6).Value <> Field6 Then
        Debug.Print "No Match"
       .Edit
           .Fields(6).Value = Field6
       .Update
    Else
        Debug.Print "!!Match Found!!"
    End If
    .MoveNext
Wend
.Requery
End With
'Refreshes DPAR Counter
Me.Customer.SetFocus
Me.Dirty = True
Me.Refresh

End Sub

1 个答案:

答案 0 :(得分:0)

应该是:

Dim Field6 As Variant
With Me!SubformCONTROLName.Form.RecordsetClone
    If .RecordCount > 0 Then
        .MoveFirst
    End If
    While Not .EOF
        Field6 = DLookup("OverallStatus", "tDPARSHEET", "[LocalPartNumber]='" & .Fields(3).Value & "' AND [LocalRevision]='" & .Fields(4).Value & "'") The
        Debug.Print .Fields(6).Name, .Fields(6).Value, Field6
        If .Fields(6).Value <> Field6 Then
            Debug.Print "No Match"
           .Edit
               .Fields(6).Value = Field6
           .Update
        Else
            Debug.Print "!!Match Found!!"
        End If
        .MoveNext
    Wend
    .Requery
End With