how to insert attachment in sharepoint list using ado access vba (1 Viewer)

atzdgreat

Member
Local time
Today, 07:52
Joined
Sep 5, 2019
Messages
37
hi all. i dont know how to insert an attachment in sharepoint list using ado.

Code:
Dim objStream As ADODB.Stream
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim pdfPath As String
    Dim strSQl As String
    pdfPath = "C:\Users\xxxx\Documents\24-0001.pdf"
    Set objStream = New ADODB.Stream
    objStream.Type = 1
    objStream.Open
    objStream.LoadFromFile pdfPath
  
    Set conn = New ADODB.Connection
    Set conn = CurrentProject.Connection
    
    'get Organization
    Set rs = New ADODB.Recordset
    strSQl = "SELECT Attachments FROM FDRFMainRequestTable WHERE FDRFRefNum = '24-0001'"
    rs.Open strSQl, conn, adOpenKeyset, adLockOptimistic
    
    If rs.EOF Then
    Else
        rs.Fields("Attachments") = objStream.Read
        rs.Update
    End If
    
    rs.Close
    Set rs = Nothing
    
    conn.Close
    Set conn = Nothing
  
    Set objStream = Nothing
    MsgBox ("Done!")
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:52
Joined
Jul 9, 2003
Messages
16,431
I note that you have yet to receive a reply. I am writing this message to bump you up the list so that your question gets a second look.
 

GPGeorge

George Hepworth
Local time
Today, 07:52
Joined
Nov 25, 2004
Messages
2,093
hi all. i dont know how to insert an attachment in sharepoint list using ado.

Code:
Dim objStream As ADODB.Stream
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim pdfPath As String
    Dim strSQl As String
    pdfPath = "C:\Users\xxxx\Documents\24-0001.pdf"
    Set objStream = New ADODB.Stream
    objStream.Type = 1
    objStream.Open
    objStream.LoadFromFile pdfPath
 
    Set conn = New ADODB.Connection
    Set conn = CurrentProject.Connection
   
    'get Organization
    Set rs = New ADODB.Recordset
    strSQl = "SELECT Attachments FROM FDRFMainRequestTable WHERE FDRFRefNum = '24-0001'"
    rs.Open strSQl, conn, adOpenKeyset, adLockOptimistic
   
    If rs.EOF Then
    Else
        rs.Fields("Attachments") = objStream.Read
        rs.Update
    End If
   
    rs.Close
    Set rs = Nothing
   
    conn.Close
    Set conn = Nothing
 
    Set objStream = Nothing
    MsgBox ("Done!")
What happens when you run this code? Knowing that might help someone cue in on a possible suggested solution.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:52
Joined
Oct 29, 2018
Messages
21,628
Does it have to be ADO? Can you try DAO?
 

Users who are viewing this thread

Top Bottom