Sub outsp()
Dim strsp As String
Dim quantity As Integer
Dim cNum As String
strsp = "a" '商品名称
quantity = 3 '数量
cNum="a303" '出库编号
Call writer_out(strsp, quantity, cNum)
End Sub
Sub writer_out(ByVal mc As String, ByVal sl As Integer, ByVal strNum As String)
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim strCon As String
Dim dj As Double
Dim nCount As Integer
Dim out_quantity As Integer
strCon = "provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\db_sjk.ACCDB;Persist Security Info=False"
cn.Open strCon
Dim strSql As String
strSql = "select * from tb_in where 名称='" & mc & "' and 库存量>0 order by id"
rs.Open strSql, cn, adOpenKeyset, adLockOptimistic
Do While Not rs.EOF
nCount = nCount + rs("库存量").Value
rs.MoveNext
Loop
rs.MoveFirst
If sl > nCount Then
MsgBox "你出库的数量太大!"
rs.Clone
cn.Close
Exit Sub
End If
Do While True
If sl <= rs("库存量").Value Then
dj = rs("单价").Value
strSql = "insert into tb_out(名称,单价,出库数量,出库编号) values('" & mc & "'," & dj & "," & sl & ",'" & outNum & "')"
cn.Execute strSql
rs("出库数量").Value = rs("出库数量").Value + sl
rs("库存量").Value = rs("入库数量").Value - sl
rs("出库总额").Value = rs("出库数量").Value * rs("单价").Value
rs("库存余额").Value = rs("库存量").Value * dj
rs.Update
Exit Do
Else
dj = rs("单价").Value
out_quantity = rs("库存量").Value
strSql = "insert into tb_out(名称,单价,出库数量,出库编号) values('" & mc & "'," & dj & "," & out_quantity & ",'" & strNum & "')"
cn.Execute strSql
rs("出库数量").Value = rs("出库数量").Value + out_quantity
sl = sl - rs("库存量").Value
rs("库存量").Value = 0
rs("出库总额").Value = rs("出库数量").Value * rs("单价").Value
rs("库存余额").Value = rs("库存量").Value * dj
rs.MoveNext
End If
Loop
rs.Update
rs.Clone
cn.Close
End Sub