Dim bian, ku, wan, wei, qi, qian, zi
Dim e As Currency
Dim ri As Date
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim strXs As String
Dim check
check = True
bian = " [商品编号] ='" & Forms![销售出库]![销售出库子窗体]![商品编号] & "'"
wan = "[完结]=" & False
wei = Forms![销售出库]![销售出库子窗体]!数量
Set db = CurrentDb()
strXs = "select 库存表.日期,库存表.库存量,库存表.完结,库存表.商品进价 from 库存表 where 库存表.商品编号 = '" & Forms!销售出库!销售出库子窗体!商品编号 & "'" & "and 库存表.完结 = " & False & ""
Set rec = db.OpenRecordset(strXs, dbOpenDynaset)
'ri = DMin("日期", "库存表")
'rec.FindFirst "[日期]=# " & Forms!销售出库!销售出库子窗体!单据日期 & "#"
Do While wei < 0 Or Not rec.EOF
If rec("库存量") > wei Then
rec.Edit
rec("库存量") = rec("库存量") - wei
Forms![销售出库]![销售出库子窗体]![进货价] = rec("商品进价")
rec.Update
Exit Do
Else
rec.Edit
wei = wei - rec("库存量")
Forms![销售出库]![销售出库子窗体]![进货价] = rec("商品进价")
rec("库存量") = 0
rec("完结") = True
rec.Update