|
lin2003_lin 发表于 2011-12-22 15:27
不希望增加一字段,而是将“分配后余额”直接代替元“剩余数量” - Private Sub Command0_Click()
- Dim rs As New ADODB.Recordset
- Dim rst As New ADODB.Recordset
- Dim cnn As New ADODB.Connection
- Dim sSQL As String
- Dim lngBal As Long
- Set cnn = CurrentProject.Connection
- sSQL = "select 类别,剩余数量 from b"
- rs.Open sSQL, cnn, adOpenKeyset, adLockOptimistic
- Do While Not rs.EOF
- lngBal = rs.Fields("剩余数量")
- sSQL = "select * from a where 类别='" & rs.Fields("类别") & "'"
- rst.Open sSQL, cnn, adOpenKeyset, adLockOptimistic
- With rst
- Do While Not .EOF
- If .Fields("差额") <> 0 Or lngBal <> 0 Then
- If lngBal >= Abs(.Fields("差额")) Then
- .Fields("配额") = .Fields("配额") + Abs(.Fields("差额"))
- lngBal = lngBal - Abs(.Fields("差额"))
- Else
- .Fields("配额") = .Fields("配额") + lngBal
- lngBal = 0
- End If
- .Fields("差额") = .Fields("配额") - .Fields("需求数额")
- .Update
- rs.Fields("剩余数量") = lngBal
- rs.Update
- End If
- .MoveNext
- Loop
- .Close
- End With
- rs.MoveNext
- Loop
- Me.a.Requery
- Me.b.Requery
- rs.Close
- Set rs = Nothing
- Set rst = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|