|
其实你这个list2只是显示下数据,又簿输入数据,可以用汇总查询作为他的行来源,省去了记录合并的代码。
还是按你的要求办,
1. 将list2的行来源更改为- SELECT 账单.编号, 账单.商品系列, 账单.数量, 账单.总价
- FROM 账单
- WHERE (((账单.商品系列) Not Like "abc系列"))
- ORDER BY 账单.商品系列;
复制代码 2. 增加更新abc系列的代码,更改如下(其他不变)
- Private Sub List0_DblClick(Cancel As Integer)
- Dim rs As New ADODB.Recordset
- Dim strSQL, SQL As String
- Dim lngOldQty As Long
- Dim curOldAmt As Currency
- strSQL = "Insert into 账单(商品系列,数量,总价)values('" & Me.List0.Column(2) & "',1," _
- & Me.List0.Column(3) & ")"
- CurrentDb.Execute strSQL '追加记录
- SQL = "select * from 账单 where 商品系列='" & Me.List0.Column(2) & _
- "' order by 编号"
- rs.Open SQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
- If rs.RecordCount = 2 Then
- lngOldQty = rs!数量
- curOldAmt = rs!总价
- rs.Delete '合并记录
- rs.MoveNext
- rs!数量 = rs!数量 + lngOldQty
- rs!总价 = rs!总价 + curOldAmt
- rs.Update
- End If
- rs.Close
- Set rs = Nothing
- Me.List2.Requery
- GetTotal
- SQL = "Update 账单 set 数量=" & Me.Text6 & ",总价=" & Me.Text8 & _
- " where 商品系列='abc系列'"
- CurrentDb.Execute SQL
- End Sub
复制代码
[ 本帖最后由 Henry D. Sy 于 2008-11-26 20:19 编辑 ] |
|