MS Access中的错误:运行时错误“ 424”:必需对象

时间:2018-09-23 02:29:33

标签: sql vba ms-access

我当前正在制作一个按钮,该按钮应该使用子窗体(链接到另一个表)中的数据更新表。应该只获取那些用户已选中其复选框(fldFlag)的记录的数据。

这是我遇到问题的代码

If tblCoverageBatch.fldFlag = True Then

如果有帮助,请在整个代码下方找到

Private Sub CmdAssignSTOT_Click()
'Declarations
Dim ask As String
Dim x As Integer
Dim DB As DAO.Database
Dim rst As DAO.Recordset
'popup message box to confirm save
ask = MsgBox("Do you want to save new STOT entry?", vbQuestion + vbYesNo, "System message...") = vbYes
    If ask = True Then
        'initialize value of incrementing variable x
        x = 0
        Set DB = CurrentDb
        Set rst = DB.OpenRecordset("STOTCoverageBatchAssigned") 'setting the table
        Do While x < DCount("[ID]", "[STOTCoverageBatchUnassigned]") 'actions below to be performed until the last record
            If tblCoverageBatch.fldFlag = True Then 'actions below will only be performed when their tickbox fldFlag is ticked.
                With rst 'encoding!
                .Edit
                    ![STOTNo] = Me.STOTNo
                    ![STOTDate] = Me.STOTDate
                    ![BatchNo] = STOTCoverageBatchUnassigned.BatchNo
                    ![PCICCheck] = STOTCoverageBatchUnassigned.CompleteDocsPCIC
                    ![ARBCheck] = STOTCoverageBatchUnassigned.CompleteDocsARB
                    ![PCICDocsReceivedDate] = STOTCoverageBatchUnassigned.PCICDocsReceivedDate
                    ![ARBDocsReceivedDate] = STOTCoverageBatchUnassigned.ARBDocsReceivedDate    
                .Update
                End With
                x = x + 1 'increment x by 1 to move on to the next record
            End If
        Loop
    Me.STOTNo.Value = Nz(DLast("STOTNo", "tblSTOT"), 0) + 1 'increment STOT number in the STOTNo field  only when actions above have been performed
    End If
End Sub`

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试一下:

Private Sub CmdAssignSTOT_Click()

    'Declarations
    Dim ask As Boolean
    Dim x As Integer
    Dim DB As DAO.Database
    Dim rst As DAO.Recordset

    'popup message box to confirm save
    ask = MsgBox("Do you want to save new STOT entry?", vbQuestion + vbYesNo, "System message...") = vbYes

    If ask = True Then
        'initialize value of incrementing variable x
        Set DB = CurrentDb
        Set rst = DB.OpenRecordset("STOTCoverageBatchAssigned") 'setting the table

        While Not rst.EOF
            If rst.fldFlag.Value = True Then 'actions below will only be performed when their tickbox fldFlag is ticked.
                With rst 'encoding!
                    .Edit
                        ![STOTNo] = Me.STOTNo
                        ![STOTDate] = Me.STOTDate
                        ![BatchNo] = Me!STOTCoverageBatchUnassigned.BatchNo
                        ![PCICCheck] = Me!STOTCoverageBatchUnassigned.CompleteDocsPCIC
                        ![ARBCheck] = Me!STOTCoverageBatchUnassigned.CompleteDocsARB
                        ![PCICDocsReceivedDate] = Me!STOTCoverageBatchUnassigned.PCICDocsReceivedDate
                        ![ARBDocsReceivedDate] = Me!STOTCoverageBatchUnassigned.ARBDocsReceivedDate    
                    .Update
                    .MoveNext
                End With
                Me!STOTNo.Value = Nz(DMax("STOTNo", "tblSTOT"), 0) + 1 'increment STOT number in the STOTNo field  only when actions above have been performed
            End If
        Wend
        rst.Close
    End If

但是,它将仅在子窗体中使用当前记录,我不知道您是否想要什么,因为尚不清楚您要完成什么。     结束