Add pdf as attachment when adding new item to SP List VBA

Viewed 70

I found the code to add a new entry to a sharepoint list, but I would also like to attach a file to that line when I add the item. I was able to add the item without that attachment, but I get a "member not found" when I try to upload a pdf to either a custom column or the attachments column. I appreciate any assistance.

    Dim cnt As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim adoStream As ADODB.Stream
    
    Dim mySQL As String
    Set adoStream = New ADODB.Stream
    Set cnt = New ADODB.Connection
    Set rst = New ADODB.Recordset
    
    mySQL = "SELECT * FROM [findDatatb];"
    
    With cnt
        .connectionString = _
        "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX-0;RetrieveIds=Yes;DATABASE=sharepointList;"
        .Open
    End With
    
    rst.Open mySQL, cnt, adOpenDynamic, adLockOptimistic
    adoStream.Open
    adoStream.LoadFromFile FilePath
    rst.AddNew
    
    rst.Fields("Project Leader") = "Test"
    rst.Fields("Implementation Team") = "test"
    rst.Fields("Completion Date") = "5/12/22"
    rst!Benefit = 6
    rst!Cost = 7
    rst.Fields("B/C Ratio") = 8
    rst!Status = "Submitted"
    rst.Fields("PDF Export") = adoStream
    adStream.Close
    
    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
0 Answers
Related