|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
本帖最后由 maxiwen 于 2009-4-10 16:37 编辑
在用友ERP企业平台中查询出入库流水帐,只可查到本年度的,
但有时想查某个存货编码的所有出入库流水帐,在平台中就有些不方便了,
最近研究出了,通过EXCEL文档VBA+SQL成功写了出入库流水帐EXCEL外挂查询程序
这样的外挂还可以写:采购到货未完成、现存量查询、生产订单领料查询等等
因为办公室人员一般都用EXCEL,报表调节方便简单,通过VBA+SQL的EXCEL程序查询出入库流水帐不需要登录用友企业平台,打开一个EXCEL文档即可查询,这样不受用友ERP的用户登录名额限额,运行速度也快!
特别方便! 有兴趣的或VBA爱好者 交流交流 QQ:335622269
根据公司实际情况写的代码如下:
Sub OutInlistQuery() '出入库流水帐查询
Dim row_Dst As Long, txt_Msg As String, tmp_Ans As VbMsgBoxResult
Sheet20.Visible = True
Sheet20.Select
Range("a1").Select
Sheet20.Range("a1:iv65536").ClearContents
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
Dim strConn As String
strConn = "PROVIDER=SQLOLEDB;"
strConn = strConn & "DATA SOURCE=服务器名或IP地址;INITIAL CATALOG=数据库帐套名称;"
strConn = strConn & "User Id=sa Password=sa密码; "
cnPubs.Open strConn
Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset
Range("a1") = "类别"
Range("b1") = "日期"
Range("c1") = "单据号"
Range("D1") = "存货编码"
Range("E1") = "存货名称"
Range("F1") = "单位"
Range("G1") = "数量"
Range("H1") = "标识"
Range("I1") = "备注"
Range("J1") = " 销售订单号"
Range("K1") = "生产订单号"
Range("L1") = "代号"
Select Case tmp_Case
Case 1
'a.cinvcode like '%" + str_CEA001 + "%' and G.Csocode like '%" + str_CAB001_Begin + "%' and convert(char(10),b.ddate,121) like '%" + str_RBA004_Begin + "%'
With rsPubs
.ActiveConnection = cnPubs
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open "select (case when b.cvouchtype='34'then'系统转结'else b.cbustype end )as 单据类型,convert(char(10),b.ddate,121) AS 日期,b.ccode AS 单号," & _
"a.cinvcode as 存货编码,c.cinvname as 存货名称,d.cComunitName as 单位,a.iquantity AS 数量," & _
"(case when b.brdFlag=1 then'入库'else'出库'end) as 类别 ,b.cmemo AS 备注,G.Csocode as 销售单号," & _
"isnull(b.cOrderCode,b.cmpocode) as 采购或生产订单号,b.cvouchtype" & _
" From rdrecords as a inner join " & _
"rdrecord as b on a.id=b.id left join " & _
"inventory as c on a.cinvcode=c.cinvcode left join " & _
"computationUnit as d on c.ccomunitCode=d.cComunitCode left join " & _
"so_sodetails as g on g.ISOSid=a.isodid " & _
"where G.Csocode like '%" + str_CAB001_Begin + "%' " & _
"GROUP BY (case when b.cvouchtype='34'then'系统转结'else b.cbustype end ),convert(char(10),b.ddate,121),b.ccode,a.cinvcode,c.cinvname,d.cComunitName,a.iquantity," & _
" (case when b.brdFlag=1 then'入库'else'出库'end)," & _
" b.cmemo,G.Csocode,isnull(b.cOrderCode,b.cmpocode),b.cvouchtype " & _
"ORDER BY convert(char(10),b.ddate,121),b.cvouchtype,b.ccode,(case when b.cvouchtype='34'then'系统转结'else b.cbustype end ),a.cinvcode,c.cinvname,d.cComunitName,a.iquantity," & _
" (case when b.brdFlag=1 then'入库'else'出库'end)," & _
" b.cmemo,G.Csocode,isnull(b.cOrderCode,b.cmpocode) "
Sheet20.Range("A2").CopyFromRecordset rsPubs
.Close
End With
Case Else
txt_Msg = "当前查询条件的程序未完成!"
tmp_Ans = MsgBox(txt_Msg, vbExclamation, "条件错")
End Select
cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing
Range("a2").Select
End Sub |
评分
-
查看全部评分
|