Results 1 to 4 of 4
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Import txt file into Access Table

    Hello, I have around 30 reports that run daily. These reports are always formatted the same... XXX then current date. I am able to import a single file just fine, but when trying to apply the date formatting it gives
    Run-Time Error '31519':
    You cannot import this file


    \/ this works
    Code:
    Private Sub cmdImport_Click()
    Dim FilePath As String
    
    
    FilePath = "C:\TroubleList\Atlanta\skb 05-01-2012.txt"
    DoCmd.TransferText acImportFixed, "impTroubleReport", "tblTrouble", FilePath, False
    MsgBox "Import Complete"
    I have googled this issue and found a few answers, however still running into issues... the solutions I have tried..Still giving the error.
    \/
    Code:
    Dim FilePath As String
    Dim FileDate As Date
    
    
    FileDate = Format(Now, "mm-dd-yyyy")
    
    FilePath = "C:\TroubleList\Atlanta\skb" & FileDate & ".txt"""
    FilePath = "C:\TroubleList\Atlanta\skb" & Format$(Date, "mm-dd-yyyy") & ".txt"""
    
     DoCmd.TransferText acImportFixed, "impTroubleReport", "tblTrouble", FilePath, False
    
    
     MsgBox "Import Complete"
    Hopefully its a simple issue and thats why I can't find much on google. Any advice would be great

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not sure if this is part of the issue but Format function results in a string value, not a date. Don't declare FileDate as a Date, String will do because that's really how you are using it. If you want a space between skb and the date, need to include it in the literal string part of the FilePath. I think the real issue is the triple quotes, which is causing a literal quote mark to become part of the file name.
    FilePath = "C:\TroubleList\Atlanta\skb " & FileDate & ".txt"
    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.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I see 3 problems....

    1) there are too many quotes after ".txt" there should only be one

    These reports are always formatted the same... XXX then current date.
    2) from the code example that runs, it looks like there is a space between the 'xxx' and the date. You are missing the space in the second example.

    3) is the date always like this "05-01-2012" or like this "5-1-2012"? The month and day two characters?


    Try this:
    Code:
       Dim FilePath As String
       Dim FileDate As String
    
       FileDate = Format(Date, "mm-dd-yyyy")
       FilePath = "C:\TroubleList\Atlanta\skb " & FileDate & ".txt"
    
       DoCmd.TransferText acImportFixed, "impTroubleReport", "tblTrouble", FilePath, False
    
    
       MsgBox "Import Complete for file: '" & Right(FilePath, 18) & "'"
    or you can use
    Code:
       Dim FilePath As String
    
       FilePath = "C:\TroubleList\Atlanta\skb " & Format(Date, "mm-dd-yyyy") & ".txt"
    
       DoCmd.TransferText acImportFixed, "impTroubleReport", "tblTrouble", FilePath, False
    
       MsgBox "Import Complete for file: '" & Right(FilePath, 18) & "'"

  4. #4
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Code:
    
       Dim FilePath As String   Dim FileDate As String   FileDate = Format(Date, "mm-dd-yyyy")   FilePath = "C:\TroubleList\Atlanta\skb " & FileDate & ".txt"   DoCmd.TransferText acImportFixed, "impTroubleReport", "tblTrouble", FilePath, False   MsgBox "Import Complete for file: '" & Right(FilePath, 18) & "'"
    This worked beautifully, thank you very much! code now has a mention of

    'ssanfu and june7 made this import possible, from accessforums.net

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

Similar Threads

  1. Import Excel file to Access
    By emmett in forum Import/Export Data
    Replies: 3
    Last Post: 04-06-2012, 05:27 AM
  2. Replies: 2
    Last Post: 01-26-2012, 12:19 PM
  3. Replies: 0
    Last Post: 12-08-2011, 09:12 AM
  4. Replies: 5
    Last Post: 10-28-2011, 12:20 PM
  5. How to import a .dta file into Access 2010?
    By Louie in forum Import/Export Data
    Replies: 4
    Last Post: 07-26-2011, 06:14 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