|
本帖最后由 浠朢↘恠明兲 于 2018-8-17 19:33 编辑
用了EH2003作者的[分享] 连接access或SqL2000数据库全局变量方法(增加示例)
http://club.excelhome.net/thread-894274-1-1.html
请问如果要插入新记录改怎么插入?
- Cnn.ExecuteSQL = "Insert Into 售出 " & Sql '插入新记录SQL语句
复制代码 这样不行
- Public cnn As ADODB.Connection
- Public rst As ADODB.Recordset
- Public msg As String
- Public sql As String '创建字符串变量
- Public Function ExecuteSQL(sql As String) As ADODB.Recordset
- On Error GoTo executesql_error
- Set cnn = New ADODB.Connection
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & "\db1.mdb" '连接access的方法
- Set rst = New ADODB.Recordset
- rst.Open Trim$(sql), cnn, adOpenKeyset, adLockOptimistic
- Set ExecuteSQL = rst
- executesql_exit:
- Set rst = Nothing
- Set cnn = Nothing
- Exit Function
- executesql_error:
- msg = "错误原因:" & Err.Description
- Resume executesql_exit
- End Function
复制代码 自己测试已解决:- Set Rst = ExecuteSQL("Insert Into 售出 " & Sql)
复制代码 SQL语句里EXCEL版本不知道为什么12.0就不行,8.0就可以
|
|