循环访问记录集

时间:2014-06-13 07:52:29

标签: ms-access access-vba recordset

我试图让记录集循环代码工作,我有我的波纹管代码,一直输入零。我的第二段代码是相同的代码,但在消息框中显示数量。它显示的数字是我想输入到我的字段中的数字。我似乎无法让它把数字放在现场!数量?

Dim Val As Integer
Dim rs As DAO.Recordset
Set rs = Forms!frmReceive!sfrmReceiveDetailEntry.Form.RecordsetClone
With rs
Do While Not rs.EOF

rs.Edit
Val = Nz(DLookup("[RemainingQty]", "tblQtySoFarTEMP", "[OrderDetailPK]= " & rs!    [OrderDetailFK]))
rs!Qty = Val
rs.Update

rs.MoveNext
Loop
End With
Set rs = Nothing

在消息框中显示值

Dim val As Integer

Dim rs As DAO.Recordset
Set rs = Forms!frmReceive!sfrmReceiveDetailEntry.Form.RecordsetClone
With rs
Do While Not rs.EOF
val = Nz(DLookup("[RemainingQty]", "tblQtySoFarTEMP", "[OrderDetailPK]= " & rs! [OrderDetailFK]))

MsgBox val

rs.MoveNext
Loop
End With
Set rs = Nothing

1 个答案:

答案 0 :(得分:0)

我最终解决了这个问题,这是我的工作代码!

'If YES then run the following code
AreYouSure = MsgBox("You are about to Receive All of Order" & txtOrderNumber.Value & " ,   Are you Sure?, The whole order and it's Quantities will be updated?", vbYesNo, "Receive  All?")
If (AreYouSure = vbYes) Then
'disable warnings
DoCmd.SetWarnings False
'Create recordsetclone of subform
'loop recordset and lookup remaining qty to receive all
Set rs = Forms!frmReceive!sfrmReceiveDetailEntry.Form.RecordsetClone
   With rs
      Do While Not rs.EOF

       rs.Edit
       rs("Qty") = Nz(DLookup("[RemainingQty]", "tblQtySoFarTEMP", "[OrderDetailPK]= " & rs![OrderDetailFK]))
       rs.Update
       rs.MoveNext
      Loop
  End With
Set rs = Nothing