|
楼主 |
发表于 2012-4-23 08:17
|
显示全部楼层
对查询进行了改进,因为同一供应商,同一时间里面有可能有挂账也有现金的,以前没有这方面的考虑,先对其代码修改。。- Private Sub CommandButton1_Click()
- Application.ScreenUpdating = False
- Dim arr As Variant
- Dim x As Long
- Dim j As Long
- Range("a:O").ClearContents
- If b Then
- arr = Array("入库日期", "品名规格", "单位", "入库数量", "入库单价", "入库金额", "指令单号", "合同号", "生产批号", "货号", "采购类别", "供应商", "单据编号")
- Else
- arr = Array("入库日期", "品名规格", "单位", "入库数量", "入库单价", "入库金额", "指令单号", "合同号", "生产批号", "货号", "采购类别", "采购员", "单据编号")
- End If
- Range("a1:m1") = arr
- If ComboBox1.Text = "请选择" Then
- MsgBox "没有选择"
- Unload Me
- Exit Sub
- End If
- Dim cnn As New ADODB.Connection
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
- If b Then
- Sql = "select * from [入库$] where 采购类别='挂账' and 供应商或采购员='" & ComboBox1.Text & "'"
- Else
- Sql = "select * from [入库$] where 采购类别='现金' and 供应商或采购员='" & ComboBox1.Text & "'"
- End If
- [a2].CopyFromRecordset cnn.Execute(Sql)
- cnn.Close
- Set cnn = Nothing
- j = [L65536].End(xlUp).Row + 1
- With Worksheets("查询")
- .Cells(j, 1) = "本月合计"
- .Cells(j, 4).Formula = "=sum(d2:d" & j - 1 & ")"
- .Cells(j, 6).Formula = "=sum(f2:f" & j - 1 & ")"
- End With
- Application.ScreenUpdating = True
- Unload Me
- End Sub
复制代码
|
|