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

atzdgreat

Member
Local time
Today, 11:01
Joined
Sep 5, 2019
Messages
32
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, 19:01
Joined
Jul 9, 2003
Messages
16,282
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

Grover Park George
Local time
Today, 11:01
Joined
Nov 25, 2004
Messages
1,878
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, 11:01
Joined
Oct 29, 2018
Messages
21,479
Does it have to be ADO? Can you try DAO?
 

Users who are viewing this thread

Top Bottom