|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
建议楼主,先看一下insert into 数据的是怎么样用的。
Set cn = CreateObject("ADODB.Connection")
On Error GoTo 100
cn.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.Path & "\Data.accdb"
sql = "insert into Table1 values('" _
& TextBox1 & "',#" _
& TextBox2 & "#," _
& TextBox3 & ",'" _
& TextBox4 & "',null)"
MsgBox sql
cn.Execute (sql)
cn.Close
Set cn = Nothing
Unload Me
Exit Sub
100:
cn.Close
Set cn = Nothing
MsgBox Error$(Err.Number)
End Sub
Private Sub CommandButton1_Click()
Dim cn As Object, sql As String
Set cn = CreateObject("ADODB.Connection")
On Error GoTo 100
cn.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.Path & "\Data.accdb"
sql = "insert into Table1 values('" _
& TextBox1 & "'," _
& "null,null,null,#" _
& TextBox2 & "#)"
cn.Execute (sql)
cn.Close
Set cn = Nothing
Unload Me
Exit Sub
100:
cn.Close
Set cn = Nothing
MsgBox Error$(Err.Number)
End Sub |
|