+ Reply to Thread
Results 1 to 1 of 1

How to use Excel as User Interface with Access DB, w/ both files on Sharepoint

Hybrid View

  1. #1
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    How to use Excel as User Interface with Access DB, w/ both files on Sharepoint

    Can someone provide example connection VBA code for connecting Excel Table to an Access DB file with both files stored on Sharepoint?
    I want to use Excel as the user interface for entering & editing data that then uses VBA in order to write the data to an Access DB file.
    I know how to do this with both files stored on normal computer drive folders, but I do not know how to do the connection & update commands when both files are on Sharepoint.
    I'm unable to find help via searching the internet.
    Any help is appreciated!

    Later on 3-3-2024, I edited this post so to add the following text to it. I am hoping that by showing the VBA for non-https pathways that this may facilitate assistance on finding the code for a https pathway.

    Below is the VBA for Excel to connect to Access via standard, non-https pathways. Notice the comment line at the 3rd line for a https pathway. If I enable this line, the connection does not work.
    NOTE: For security reasons, I have altered this comment line so to hide company sensitive information.
    I have been unable to find help on this over the internet.
    Any help on making this connection "https friendly" would be greatly appreciated. Thank you!

    Option Explicit
    Public Const DB_Path = "C:\Users\sauerj\OneDrive - Tate & Lyle\Desktop\OE Action Tracker_Rev2_Beta.accdb"
    'Public Const DB_Path = "https://company.sharepoint.com/:u:/s/SP_Group/AAAAAAAABBBBBBBCCCCCCCDDDDDDDEEEEEEFFFFFF?e=987654321"
    Public Const ModName = "u_OE_DB_Macros"
    
    '**********************************************************************************************************************
    Sub Edit_ActionList_DB()
    Dim Sht As Worksheet, SNR7 As String, SNL3 As String, Cel As Range    ', DB_Path As String
    Dim Conn As ADODB.Connection, RS As ADODB.Recordset, Qry As String
    Dim i As Integer
    Const MacroName = "Edit_ActionList_DB"
    
    100   On Error GoTo Errorhandler
    101   Set Sht = ActiveSheet
    102   SNR7 = Right(Sht.Name, 7)
    103   If SNR7 <> "Pending" And SNR7 <> "Complet" Then Exit Sub
    104   SNL3 = Left(Sht.Name, 3)
    
    105   Set Conn = New ADODB.Connection
    106   With Conn
    107     .Provider = "Microsoft.ACE.OLEDB.12.0"
    108     .Open DB_Path
    109   End With
    
    110   Set RS = New ADODB.Recordset
    
    111   Range(Sht.Cells(4, 1), Sht.Cells(100000, 1).End(xlUp)).Select
    
    112   For Each Cel In Application.Selection
    113     If Cel.Address = "$A$1" Then
    114       MsgBox "Nothing was selected to update"
    115       Application.Goto Range("A1"), True
    116       ActiveWindow.VisibleRange(1, 1).Select
    117       Exit Sub
    118     End If
      
    119     If Cel <> vbNullString Then
    
    120       If Cel.Offset(0, 1) = vbNullString Then                              'If true, then this line is a new action item
    121          Qry = "SELECT * " & _
                        "FROM [Action_List_Table] "
    122          RS.Open Qry, Conn, adOpenDynamic, adLockOptimistic
    123          RS.AddNew
    124         Else
    125          Qry = "SELECT * " & _
                       "FROM [Action_List_Table] " & _
                       "WHERE [Action_List_Table]!ID = " & Cel.Offset(0, 1)
    126          RS.Open Qry, Conn, adOpenDynamic, adLockOptimistic
              End If
    
    127       RS.Fields("Meeting_Type") = Cel.Offset(0, 2)  'UCase(SNL3)                              'C
    128       If SNR7 = "Pending" Then
    129           RS.Fields("Pending_or_Completed_Sheet") = "Pending"
    130         Else
    131           RS.Fields("Pending_or_Completed_Sheet") = "Completed"            'C
    132       End If
    133       RS.Fields("Problem_Project_Name") = Cel.Offset(0, 3)
    134       RS.Fields("Action_Item") = Cel.Offset(0, 4)
    135       RS.Fields("Status") = Cel.Offset(0, 5)
    136       RS.Fields("Owner_Initials") = Cel.Offset(0, 6)
    137       RS.Fields("Date_Due") = Cel.Offset(0, 7)
    138       RS.Fields("Date_Completed") = Cel.Offset(0, 8)
    139       If SNR7 = "Pending" Then
    140           RS.Fields("Archive_Action_for_Pending_Items") = Cel.Offset(0, 9)
    141         Else
    142           RS.Fields("Archived_Status_for_Completed_Items") = Cel.Offset(0, 9)    'C
    143       End If
    144       RS.Fields("Date_Added") = Now()
    145       RS.Fields("Last_Updated_By") = ActiveWorkbook.WriteReservedBy
    146       RS.Update
    147       Cel.Value = vbNullString
    148       RS.Close
    149     End If
    150   Next
    
    151   Conn.Close
    
    152   Refresh_Data
        
    200    GoTo Label_End
    '**********************************************************************************************************************
    '******* Execute the Errorhandler Section. And make sure App.Events is re-enabled if a macro error occurs.   **********
    '*******                 Display Error #, Description, Bad Code Line, Macro & Module Names                   **********
    '**********************************************************************************************************************
    Errorhandler:
    201    MsgBox "Error #" & Err.Number & " has occurred." & NL & NL & _
                  "Error Description: """ & Err.Description & """" & NL & NL & _
                  "The Error ocurred on Line #" & Erl & " of " & NL & _
                  "Macro: """ & MacroName & """ located in" & NL & _
                  "Module: """ & ModName & """.", vbCritical, "Macro Error Information:"
    Label_End:
    202    Application.EnableEvents = True                                         'Re-enable Events in Application.
    End Sub
    '**********************************************************************************************************************
    
    
    '**********************************************************************************************************************
    Sub Refresh_Data()
        Application.ScreenUpdating = False
        Worksheets("ACC.Pending").Activate                                     'Load data to this Named Range
        ActiveSheet.ListObjects("qryACC.Pending").DataBodyRange.Select
        ActiveSheet.ListObjects("qryACC.Pending").QueryTable.Refresh BackgroundQuery:=False
        Application.Goto Range("A1"), True
        ActiveWindow.VisibleRange(1, 1).Select
    End Sub
    '**********************************************************************************************************************
    Last edited by sauerj; 03-03-2024 at 10:36 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Restrict user access to a drop down field to an excel file in Sharepoint
    By cseahalign in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-28-2022, 07:53 AM
  2. Replies: 0
    Last Post: 08-28-2022, 12:01 PM
  3. can vba access an external interface to load csv files through a specific file
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2017, 01:27 PM
  4. Replies: 0
    Last Post: 03-14-2016, 12:21 PM
  5. Access to Excel-files on Sharepoint site
    By jaap85 in forum Excel General
    Replies: 3
    Last Post: 02-27-2012, 11:12 AM
  6. Copy Data from Excel Files (from a Sharepoint) to Access MDB File
    By LordMarcus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2009, 05:59 AM
  7. User Interface for Viewing a Collection of Data Files
    By JKramer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2006, 05:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1