【问题标题】:SHAREPOINT VBA EXCEL ADDOB record addNewSHAREPOINT VBA EXCEL ADDOB 记录 addNew
【发布时间】:2021-02-14 11:28:48
【问题描述】:

我可以在一个空列表中添加新数据,但是当列表被填满时。当列表中有元素时我遇到问题。我有以下显示的错误消息: “行句柄引用了已删除的行或标记为删除的行”

代码如下:

Option Explicit 
Sub AddNew_SP()
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim mySQL As String
Dim intRowActive As Integer
Dim intcolumnActive As Integer

Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
intRowActive = ActiveCell.Row
intcolumnActive = ActiveCell.Column
 mySQL = "SELECT * FROM [test Prestations actif] WHERE [Test] = '" + Sheets("Plannification").Cells(intRowActive, 2).Value + "'And [Date] = #" + Format(Sheets("Plannification").Cells(6, intcolumnActive).Value, "dd/MM/yyyy") + "#;"


With cnt
    .ConnectionString = _
    "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE= url;LIST={47D821D1-325A-44CC-A22A-E838B6C6B8E1};"
    .Open
End With

rst.Open mySQL, cnt, adOpenDynamic, adLockOptimistic

rst.AddNew
    rst.Fields(1) = "Nom1"
    rst.Fields(2) = "PréNom1"
    rst.Fields(3) = "addresse"



rst.Update

If CBool(rst.State And adStateOpen) = True Then rst.Close
Set rst = Nothing
If CBool(cnt.State And adStateOpen) = True Then cnt.Close
Set cnt = Nothing

End Sub

你能帮帮我吗?

【问题讨论】:

    标签: sql excel vba sharepoint


    【解决方案1】:

    尝试使用 INSERT 语句

    Sub AddNew_SP()
    
        Const mySQL = "INSERT INTO [test1] VALUES (?,?,?)"
        
        Dim cnt As new adodb.Connection
        With cnt
            .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
             "DATABASE= URL;LIST={47D821D1-325A-44CC-A22A-E838B6C6B8E1};"
            .Open
        End With
        
        Dim cmd As adodb.Command
        Set cmd = New adodb.Command
        With cmd
            .ActiveConnection = cnt
            .CommandText = mySQL
            .CommandType = 1 'adCmdText
            .Parameters.Append .CreateParameter("P1", adVarChar, 1, 10) ' varchar(10)
            .Parameters.Append .CreateParameter("P2", adVarChar, 1, 10) ' 1 = adParamInput
            .Parameters.Append .CreateParameter("P3", adVarChar, 1, 10) '
        End With
        
        ' new record
        Dim n As Integer, ar
        ar = Array("Nom1", "PréNom1", "address")
        cmd.Execute n, ar
        
        MsgBox n & " record(s) inserted", vbInformation, "Done"
            
        If CBool(cnt.State And adStateOpen) = True Then cnt.Close
        Set cnt = Nothing
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      相关资源
      最近更新 更多