用VBA从excel向access插入数据
Debug的时候.Update这里报错了。不知道为啥。求原因与修改方法。谢谢啦!!DimadoRTAsObjectDimstrSQLAsStringSetadoRT=Cr...
Debug的时候.Update这里报错了。不知道为啥。求原因与修改方法。谢谢啦!!
Dim adoRT As Object
Dim strSQL As String
Set adoRT = CreateObject("ADODB.RecordSet")
strSQL = "SELECT * FROM Table1 Where False"
With adoRT
.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\Test.accdb"
.CursorLocation = 3
.CursorType = 1
.LockType = 3
.Source = strSQL
.Open
.AddNew
.Fields("Num").Value = Range("B1").Value
.Fields("Pname").Value = Range("B5").Value
.Fields("Sex").Value = Range("D5").Value
.Update
If .State = 1 Then
.Close
End If
End With
Set adoRT = Nothing 展开
Dim adoRT As Object
Dim strSQL As String
Set adoRT = CreateObject("ADODB.RecordSet")
strSQL = "SELECT * FROM Table1 Where False"
With adoRT
.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\Test.accdb"
.CursorLocation = 3
.CursorType = 1
.LockType = 3
.Source = strSQL
.Open
.AddNew
.Fields("Num").Value = Range("B1").Value
.Fields("Pname").Value = Range("B5").Value
.Fields("Sex").Value = Range("D5").Value
.Update
If .State = 1 Then
.Close
End If
End With
Set adoRT = Nothing 展开
展开全部
dim cn as adodb.connection
dim tsql as string
set cn=new adodb.connection
cn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=;dbq=d:\test.mdb"
tsql="insert into table1(Num,Pname,Sex) values('" + range("B1").value + "','" + range("B5").value + "','" + range("D5") +"')"
cn.execute tsql
set cn=nothing
dim tsql as string
set cn=new adodb.connection
cn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=;dbq=d:\test.mdb"
tsql="insert into table1(Num,Pname,Sex) values('" + range("B1").value + "','" + range("B5").value + "','" + range("D5") +"')"
cn.execute tsql
set cn=nothing
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询