private function fifo() as boolean
dim stroutno as string
dim strname as string
dim strcode as string
dim strempid as string
dim dblqty as double
dim strsql as string
dim rstmp as new adodb.recordset
dim g_adoconn as new adodb.connection
stroutno = "a"
strname = "a1"
strcode = "ab"
strempid = "ac"
dblqty = 40
fifo=false
on error goto errmsg
strsql = "select * from 入库表 where 名称='" & strname _
& "' and 代号='" & strcode & "' and 工号='" & strempid & "' " _
& "order by 入库时间"
rstmp.open strsql, g_adoconn, adopenkeyset, adlockreadonly '把g_adoconn改成你的数据库连接
g_adoconn.begintrans
do until rstmp.eof
if dblqty = 0 then exit do
if rstmp("库存数据") >= dblqty then
strsql = "update 入库表 set 库存数据=" & rstmp("库存数据") - dblqty _
& " where 名称='" & strname & "' and 代号='" & strcode & "' and 工号='" & strempid _
& "' and 入库时间=to_date('" & format(rstmp("入库时间"), "yyyy/mm/dd") & "','yyyy/mm/dd')"
g_adoconn.EXECute strsql
strsql = "insert into 出库记录 (名称,代号,工号,批次,出库单号,数量,入库时间) values('" _
& strname & "','" & strcode & "','" & strempid & "','" & rstmp("批次") & "','" _
& stroutno & "'," & dblqty & ",to_date('" & format(rstmp("入库时间"), "yyyy/mm/dd") & "','yyyy/mm/dd'))"
g_adoconn.EXECute strsql
dblqty = 0
else
strsql = "update 入库表 set 库存数据=0" _
& " where 名称='" & strname & "' and 代号='" & strcode & "' and 工号='" & strempid _
& "' and 入库时间=to_date('" & format(rstmp("入库时间"), "yyyy/mm/dd") & "','yyyy/mm/dd')"
g_adoconn.EXECute strsql
strsql = "insert into 出库记录 (名称,代号,工号,批次,出库单号,数量,入库时间) values('" _
& strname & "','" & strcode & "','" & strempid & "','" & rstmp("批次") & "','" _
& stroutno & "'," & rstmp("库存数据") & ",to_date('" & format(rstmp("入库时间"), "yyyy/mm/dd") & "','yyyy/mm/dd'))"
g_adoconn.EXECute strsql
dblqty = dblqty - rstmp("库存数据")
end if
rstmp.movenext
loop
if dblqty > 0 then
msgbox "没有这么多库存!"
g_adoconn.rollbacktrans
exit sub
end if
g_adoconn.committrans
fifo=true
rstmp.close
set rstmp = nothing
exit sub
errmsg:
g_adoconn.rollbacktrans
msgbox err.description
end function