|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Private Sub 路径_DblClick(Cancel As Integer)
- Dialog1.ShowOpen '显示打开文件对话框
- 路径.Value = Dialog1.FileName
- 店铺名称.Value = "客户王"
- End Sub
- Private Sub Command85_Click()
- On Error GoTo Err_Command85_Click
- DoCmd.SetWarnings False
- Dim conn
- Set conn = CreateObject("ADODB.Connection")
- conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties=Excel 8.0;Data Source= " & 路径.Value
- SQL = "select 产品,规格1,规格2,规格3,小计 from [订单$] Where 小计 <> 0 "
- Set rs = conn.Execute(SQL)
- While Not rs.EOF
- SQL = "insert into 订单明细([店铺名称],[产品],[规格1],[规格2],[规格3],[小计]) values('" & 店铺名称.Value & "','" & rs(0) & "','" & rs(1) & "','" & rs(2) & "','" & rs(3) & "','" & rs(4) & "')"
- DoCmd.RunSQL SQL
- rs.MoveNext
- Wend
- conn.Close
- Set conn = Nothing
- DoCmd.SetWarnings True
- MsgBox "OK"
- Exit_Command85_Click:
- Exit Sub
- Err_Command85_Click:
- MsgBox Err.Description
- Resume Exit_Command85_Click
- End Sub
复制代码 网上找到一些资料改好了,虽然能达到目的,但感觉一条记录一条记录追加在数据量大时比较慢
想改为insert into select来一次实现,但不成功,哪位大大有空帮看下,或者有没有其它更高效的方式?
[ 本帖最后由 henrylam 于 2011-7-15 19:31 编辑 ] |
|