|
致:坛内
走过路过的网友
本菜以下这VBA程序代码是可运行的
但
没有做到----防止重复导入数据
请教:应如何更改(判断条件----字段名:数据流水单号)
后附:Excel数据附件
Sub 添加字段前的一维进货数据()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim mydatabase As String
Dim mytable As String
Dim myKey As String
Dim bb As Long
Application.ScreenUpdating = False
mydatabase = "服装成品管理系统" '指定数据库
With cnn '建立与SQL Server数据库链接
.ConnectionString = "provider=sqloledb.1;" _
& "datasource=20100708-1126;" _
& "user id=sa;" _
& "password=123;" _
& "initial catalog=" & mydatabase
.Open
End With
mytable = "一维进仓录入暂存表"
rst.Open mytable, cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
For bb = 2 To Sheet1.Range("a65536").End(xlUp).Row
rst.AddNew
rst.Fields("日期") = Sheet1.Range("a" & bb).Value
rst.Fields("数据流水单号") = Sheet1.Range("b" & bb).Value
rst.Fields("单据类型") = Sheet1.Range("c" & bb).Value
rst.Fields("数据是否参与计价") = Sheet1.Range("d" & bb).Value
rst.Fields("数据是否参与库存计算") = Sheet1.Range("e" & bb).Value
rst.Fields("供货商单位编号") = Sheet1.Range("f" & bb).Value
rst.Fields("供货商单位名称") = Sheet1.Range("g" & bb).Value
rst.Fields("发货地名称") = Sheet1.Range("h" & bb).Value
rst.Fields("收货地名称") = Sheet1.Range("i" & bb).Value
rst.Fields("数据来源凭证号") = Sheet1.Range("j" & bb).Value
rst.Fields("商品款号简称") = Sheet1.Range("k" & bb).Value
rst.Fields("商品款号全称加颜色") = Sheet1.Range("l" & bb).Value
rst.Fields("码数") = Sheet1.Range("m" & bb).Value
rst.Fields("数量") = Sheet1.Range("n" & bb).Value
rst.Fields("成本价") = Sheet1.Range("o" & bb).Value
rst.Fields("成本金额小计") = Sheet1.Range("p" & bb).Value
rst.Fields("录入数据大约时间") = Sheet1.Range("q" & bb).Value
rst.Fields("操作用户名") = Sheet1.Range("r" & bb).Value
rst.Fields("备注") = Sheet1.Range("s" & bb).Value
rst.Fields("商品款号全称计算") = Sheet1.Range("t" & bb).Value
rst.Fields("请勿删除") = Sheet1.Range("u" & bb).Value
rst.Update
Next bb
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
MsgBox "数据保存完毕", vbInformation
Application.ScreenUpdating = True
End Sub
敬请各位网友指点一二
谢谢!!!
[ 本帖最后由 lym321 于 2010-8-17 12:50 编辑 ] |
|