Results 1 to 2 of 2
  1. #1
    Rob D is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    1

    File Import Loop

    Hi All, I have a simple loop written to import each file in the directory specified...I am working on Access 2010 and Windows 7. The problem is that this code only imports the first file and then hangs up forever...I am really not sure why this is happening...I used this code on a previous version of Access (2003) and it worked fine now I have to retool everything for 2010...PLEASE HELP

    Here is my code:

    Dim strPath As String
    Dim strFile As String


    strPath = Me.FilePath & "\"

    strFile = Dir(strPath & "*.xls*")
    If Len(strFile) = 0 Then
    MsgBox "No Files Found"
    Else
    Do While Len(strFile) > 0
    Debug.Print strPath & strFile

    ' Turn off the warnings
    DoCmd.SetWarnings False

    'transfers the saved attachment
    DoCmd.TransferSpreadsheet acImport, 5, "XXXXXXXXX", strPath & strFile, False, "FORM!A1:U38"


    Loop

    End If
    MsgBox "Import complete.", vbInformation, "Done"



    'Let's turn the warnings back on
    DoCmd.SetWarnings True

    Beep

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    I don't see how this code ever worked for reading multiple files in a directory. The loop is not looping through the directory. It is not even looping through a set of records to get the file names.

    Google: Access VBA list files in a folder

    http://www.allenbrowne.com/ser-59.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Import Excel file based on a date and time in file name
    By nhylan in forum Import/Export Data
    Replies: 4
    Last Post: 04-16-2013, 03:26 PM
  2. Trying to import a CSV file
    By itm in forum Access
    Replies: 1
    Last Post: 04-13-2012, 06:00 PM
  3. Import XML file
    By randolphoralph in forum Programming
    Replies: 1
    Last Post: 01-22-2010, 09:12 PM
  4. Import prn file
    By Accessshelp@work in forum Import/Export Data
    Replies: 1
    Last Post: 10-29-2009, 09:16 AM
  5. Import a .sql file?
    By Alan in forum Import/Export Data
    Replies: 1
    Last Post: 06-03-2009, 07:52 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