简体   繁体   中英

ACCESS file connection from EXCEL to SharePoint (SQL database)

I have an access connection file (.accdb) that allows me to use EXCEL (Office 365) to query a SharePoint Library. It all works great EXCEPT for new files added to that SharePoint Library. I can query for and return all data for these new files/entries but cannot get the filename for these new entries for some reason. Any help would be most appreciated.

Const SQLIMSSHAREPOINTCONNECTION = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = C:\MORGAN\MACROS\IMS_SHAREPOINT_db.accdb"

Sub routine:

Dim i As Long
Dim cn As Object
Dim rs As Object
Dim StrSql As String
Dim thePieces1() As String
Dim thePieces2() As String
Dim theFullFilename As String
Dim theShortFilename As String
       
StrSql = "SELECT [Name], [ID], [PartNumber(s)], [DateCompleted], [DocumentType], " & _
        "[WorkOrder(s)], [PurchaseOrder(s)], [SalesOrder(s)], [CustomerName(s)], [WorkCenter]" & _
        " FROM [Inspection Reports]"

Set cn = CreateObject("ADODB.Connection")
cn.Open SQLIMSSHAREPOINTCONNECTION
Set rs = CreateObject("ADODB.RECORDSET")
rs.ActiveConnection = cn
rs.Open StrSql
If Not (rs.BOF And rs.EOF) Then

    i = 1

    On Error Resume Next
    Do While Not rs.EOF

        i = i + 1
        theFullFilename = ""
        theShortFilename = ""
        ReDim thePieces1(10)

        thePieces1 = Split(rs.Fields(0), "#")
        theFullFilename = thePieces1(1)
        thePieces1() = Split(theFullFilename, "/")
        theShortFilename = thePieces1(UBound(thePieces1))

        Range("A" & i).Value = rs.Fields(1)      ' ID
        Range("B" & i).Value = theShortFilename  ' Filename
        Range("C" & i).Value = rs.Fields(2)      ' PartNumber(s)
        Range("D" & i).Value = rs.Fields(3)      ' DateCompleted
        Range("E" & i).Value = rs.Fields(4)      ' DocumentType
        Range("F" & i).Value = rs.Fields(5)      ' WorkOrder(s)
        Range("G" & i).Value = rs.Fields(6)      ' PurchaseOrder(s)
        Range("H" & i).Value = rs.Fields(7)      ' CustomerName
        Range("I" & i).Value = rs.Fields(8)      ' WorkCenter

        rs.MoveNext
        
    Loop

我不清楚您的共享点访问 Excel 连接是如何工作的,但您的记录集 (rs) 在更新共享点数据后可能需要刷新或重新查询。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM