使用FindFirst时DAO RecordSet错误3251

时间:2014-05-09 12:52:13

标签: access-vba runtime-error dao

我收到"运行时错误' 3251':此类对象不支持此操作。" 当我尝试使用时" FindFirst"在我的DAO RecordSet上。有人可以向我解释我为此错误搜索记录。我正在使用的变量返回正确的搜索值。

Private Sub ctrSend_Click()
Dim intI As Integer
Dim lst As ListBox
Dim varItem As Variant
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim qtySum As Variant
Dim qtyDiff As Variant
Dim rowMax As Variant
Dim rowUpdate As Variant

Set lst = Me![lstShipping]
Set rst = CurrentDb.OpenRecordset("ShipInv", dbOpenTable)
Set rst2 = CurrentDb.OpenRecordset("Storage", dbOpenTable)
qtySum = 0
rowMax = 0

With lst
    If .ItemsSelected.count = 0 Then Exit Sub
        For Each varItem In .ItemsSelected
            qtySum = qtySum + .Column(3, varItem)
        Next

    If Me.[ctrQtyProd] = qtySum Then
        MsgBox "Qty Selected EQUALS Qty Being Shipped.", vbOKOnly, "Confirmation Message"
    ElseIf Me.[ctrQtyProd] > qtySum Then
        MsgBox "Qty Selected LESS THAN Qty Being Shipped, please select more Inventory.", vbOKOnly, "Confirmation Message"
    Else
        qtyDiff = qtySum - Me.[ctrQtyProd]
        rowMax = lst.Column(3, lst.ItemsSelected.count)
        rowUpdate = rowMax - qtyDiff

        rst2.FindFirst "[BIN] = '" & lst.Column(0, lst.ItemsSelected.count) & "'"
        rst2![QtyProd] = lst.Column(3, lst.ItemsSelected.count)
        rst2.Update
        rst2.Close

        MsgBox "Storage Successfully Updated.", vbOKOnly, "Confirmation Message"
    End If
End With

With lst
    For Each varItem In .ItemsSelected
        rst.AddNew
        rst!Order = Me.[ctrSOrder]
        rst!EntDate = Date
        rst!ShipDate = Me.[ctrSDate]
        rst!BIN = .Column(0, varItem)
        rst!SKU = .Column(1, varItem)
        rst!Lot = .Column(2, varItem)
        rst!QtyProd = rowUpdate
        rst.Update
    Next
End With
rst.Close

Set rst = Nothing
Set rst2 = Nothing
MsgBox "Shipping List Successfully Updated.", vbOKOnly, "Confirmation Message"
End Sub

1 个答案:

答案 0 :(得分:5)

您是否尝试将记录集打开为dbOpenDynaset(缺省情况下没有在open语句中指定的枚举)或dbOpenSnapshot? Microsoft MSDN站点上的文档指定它采用这两个记录集之一。

  

找到满足指定条件的动态集或快照类型Recordset对象中的第一条记录,并使该记录成为当前记录(仅限Microsoft Access工作区)。

Microsoft MSDN article on Recordset.FindFirst