Results 1 to 2 of 2
  1. #1
    Mrdude1020 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Location
    Boone
    Posts
    11

    How to update existing tables of data from exported excel files.

    Ive tried making command buttons for each of the three tables that when you click on it, it automatically updates the tables, but it doesnt seem to be updating them. Is this the right code for that to happen?

    Private Sub Command0_Click()

    Dim strFile As String

    DoCmd.SetWarnings False

    ' Set file directory for files to be imported
    strPath = "C:\Shares\Public\Staff Public Files\Brandon Penland\US Food Product Prices Newest\"
    ' Tell it to import all Excel files from the file directory
    strFile = Dir(strPath & "*.xls*")

    ' Start loop


    Do While strFile <> ""
    ' Import file
    DoCmd.TransferSpreadsheet transfertype:=acImport, tablename:="US Food Product Prices Newest", FileName:=strPath & strFile, HasFieldNames:=True, Range:="default"
    ' Loop to next file in directory
    strFile = Dir
    Loop

    MsgBox "All data has been imported.", vbOKOnly
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    No, its a bit more than that....

    Code:
    Public Sub ImportAllFilesInDir(ByVal pvDir)
    Dim vFil, vTargT
    Dim i As Integer
    dim sSql As String
    Dim db 'As Database
    Dim fso
    Dim oFolder, oFile
    On Error GoTo errImp
    If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
    sTbl = "xlFile"
    Set db = CurrentDb
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder(pvDir)
    For Each oFile In oFolder.Files
        vFil = pvDir & oFile.Name
        If InStr(sfile, ".xls") > 0 Then      'ONLY DO EXCEL FILES  
           DoCmd.TransferSpreadsheet transfertype:=acImport, tablename:="US Food Product Prices Newest", FileName:=vFil , HasFieldNames:=True, Range:="default"
        endif   
    Next
    Set db = Nothing
    Set fso = Nothing
    Set oFile = Nothing
    Set oFolder = Nothing
    DoCmd.SetWarnings True
    Exit Sub
    errImp:
    MsgBox Err.Description, vbCritical, "ImportAllFilesInDir():" & Err
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Update Existing Access Tables with Data from Excel
    By ChelseaC in forum Import/Export Data
    Replies: 7
    Last Post: 08-10-2014, 04:28 PM
  2. Replies: 4
    Last Post: 11-21-2012, 03:17 PM
  3. VBA to Format Exported Excel Data
    By rlsublime in forum Programming
    Replies: 7
    Last Post: 04-04-2012, 03:50 PM
  4. Auto Update an Exported Excel Spreadsheet
    By halt4814 in forum Access
    Replies: 1
    Last Post: 01-18-2012, 04:30 PM
  5. Replies: 1
    Last Post: 04-13-2011, 01:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums