|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
本帖最后由 kecolikeco 于 2012-11-3 14:50 编辑
下面是U8.52产成品入库帐导入VBA代码,请大家一起修改,也是抄网友的。不确定U8.52版本,CurrentStock是否需要更新,还是系统自己更新。
- Private Sub CmdCc_Click()
- Dim i As Integer, j As Integer
- Dim conn As New ADODB.Connection '定义数据链接对象 ,保存连接数据库信息;
- Dim rs As New ADODB.Recordset '定义记录集对象,保存数据表
- Dim strCn As String, SQL As String, Ys As String '字符串变量
- Dim Hs As Integer '行数
- Dim Mid As Long, mAutoId As Long '最大单号,单号
- Hs = [A65536].End(xlUp).Row
- If Hs < 6 Then
- MsgBox "数据不存在!"
- Exit Sub
- End If
- If IsDate(Cells(3, 4)) = False Then
- MsgBox "日期格式不正确,请检查"
- Exit Sub
- End If
- ' If Not Cells(4, 4).Value = "一厂" Or Cells(4, 4).Value = "二厂" Then
- ' MsgBox "厂别不正确,请检查"
- ' Exit Sub
- ' End If
- strCn = "Provider=sqloledb;Server=c900;Database=ufdata_808_2012;Uid=sa;Pwd=x3500;" '定义数据库链接字符串
- '用友通数据库命名规则,"ufdata_" + "帐套号" + "_" + "帐套年度"
- conn.Open strCn '与数据库建立连接,如果成功,返回连接对象conn
-
-
- ' SQL = "select max(stuff(cCode,LEN(cCode),1,RIGHT(cCode,1)+1)) from RdRecord where cVouchType <> '34'" '获取最大用友系统单号
- SQL = "select max(stuff(cCode,LEN(cCode),1,RIGHT(cCode,1)+1)) from RdRecord where cBusType = '成品入库'" '获取最大用友系统单号
- Sheets("入库").[b3].CopyFromRecordset conn.Execute(SQL)
- conn.Close: Set conn = Nothing
- conn.Open strCn '与数据库建立连接,如果成功,返回连接对象conn
-
- SQL = "select cVouchType,cCode from RdRecord where cVouchType = '10' and cCode='" & Trim(Cells(3, 2)) & "'" '用友系统单据号
- rs.Open SQL, conn, 1, 1
- If Not rs.EOF Then
- MsgBox "该入库单已经存在,请检查!"
- Exit Sub
- End If
- rs.Close
- conn.Execute "sp_unbindefault 'RdRecord.ID'" '取消默认值绑定
- conn.Execute "sp_unbindefault 'RdRecords.AutoID'"
- SQL = "select max(id) as Mid from rdrecord"
- rs.Open SQL, conn, 1, 1
- If IsNull(rs!Mid) Then
- Mid = 1
- Else
- Mid = rs!Mid + 1
- End If
- rs.Close
- SQL = "select * from RdRecord order by id"
- rs.Open SQL, conn, 1, 3
- rs.AddNew
- rs!Id = Mid '主键,与RdRecords.id对应
- rs!bRdFlag = 1
- rs!cVouchType = "10" '01 采购,32 销售,想要其他代码,自己打开数据库单据类型表"VouchType"
- rs!cBusType = Trim(Cells(4, 2)) '成品入库
- rs!cSource = "库存"
- rs!cWhCode = "31" '仓库
- rs!cRdCode = "0104" '入库类别,完工入库
- rs!dDate = Cells(3, 4) '入库日期
- rs!cCode = Trim(Cells(3, 2)) '用友系统单号
- rs!cMaker = Trim(Cells(3, 7)) '制单人
- rs!cMemo = Trim(Cells(4, 7)) '产量报表上的单据编号
- rs!cDefine2 = Trim(Cells(4, 4)) '生产分厂
- rs!iMQuantity = 0 '手工导入和用友客户端输入差异调整
- rs!iproorderid = 0 '手工导入和用友客户端输入差异调整
- rs.Update
- rs.Close
-
-
- SQL = "select max(autoid) as mautoid from rdrecords"
- rs.Open SQL, conn, 1, 1
- If IsNull(rs!mAutoId) Then
- mAutoId = 1
- Else
- mAutoId = rs!mAutoId + 1
- End If
- rs.Close
- For i = 6 To Hs
- SQL = "select * from RdRecords order by autoid"
- rs.Open SQL, conn, 1, 3
- rs.AddNew
- rs!AutoId = mAutoId
- rs!cInvCode = Trim(Cells(i, 1)) '产品编码,用友编码
- rs!iQuantity = Val(Cells(i, 5)) '数量
- rs!iUnitCost = Val(Cells(i, 6)) ' 单价
- rs!iPrice = Val(Cells(i, 7)) ' 金额
- rs!iAPrice = Val(Cells(i, 7)) ' 金额
- rs!fAcost = Val(Cells(i, 6)) ' 单价
- rs!cFree2 = Val(Cells(i, 8)) '库位 cFree2
- rs!Id = Mid
- rs.Update
- rs.Close
- SQL = "select * from CurrentStock where cInvCode='" & Trim(Cells(i, 1)) & "'" '产品编码,用友编码
- '注:本程序中所有测试数据的前提是:产品编号"cInvCode"已经存在存货目录表"inventory"中,因为我不需要判断这一步,需要的自己添加.
- rs.Open SQL, conn, 1, 3
- If rs.EOF Then rs.AddNew
- rs!cWhCode = "31"
- rs!cInvCode = Trim(Cells(i, 1)) '产品编码,用友编码
- rs!cFree2 = Val(Cells(i, 8)) '库位
- rs!iQuantity = rs!iQuantity + Val(Cells(i, 5)) '数量
- rs.Update
- rs.Close
- mAutoId = mAutoId + 1
- Next
- conn.Execute "sp_bindefault 'RdRecord_ID_D','RdRecord.ID'" '恢复默认值绑定
- conn.Execute "sp_bindefault 'RdRecords_AutoID_D','RdRecords.AutoID'"
- conn.Close
- MsgBox "数据导入成功!"
- End Sub
复制代码
|
|