|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 peterpu 于 2022-12-22 08:46 编辑
下面程序不用自动编号能正常运行,但加上自动编号后运行出错。请求老师出手帮助!
Sub 自动编号出错()
Dim myCat As New ADOX.Catalog
Dim myCmd As New ADODB.Command
myData = ThisWorkbook.Path & "\自动编号.mdb"
myCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & myData
Set myCmd.ActiveConnection = myCat.ActiveConnection
'创建数据库
SQL = "CREATE TABLE " & "lc1" & "(日期 date,收盘 single)"
'SQL = "CREATE TABLE " & "lc1" & "(ID AUTOINCREMENT (1,1) primary key,日期 date,收盘 single)" '增加了自动编号
With myCmd
.CommandText = SQL
.Execute , , adCmdText
End With
'向数据库输入数据
Dim CNN As New ADODB.Connection
Dim Sj As New ADODB.Recordset
With CNN
.Provider = "microsoft.jet.oledb.4.0"
.Open myData
End With
t1 = Sheet5.Range("G13"): t2 = 888
SQL = "INSERT INTO lc1 VALUES (#" & t1 & "#," & t2 & ")"
'SQL = "INSERT INTO lc1 VALUES (AUTOINCREMENT (1,1) primary key,#" & t1 & "#," & t2 & ")" ‘运行出错!
CNN.Execute SQL
CNN.Close: Set Sj = Nothing: Set CNN = Nothing: t1 = 0: t2 = 0
Set myCat = Nothing: Set myCmd = Nothing
End Sub
|
|