Import Text Code does not see my file??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wayne L
    New Member
    • Sep 2007
    • 31

    Import Text Code does not see my file??

    Can someone tell my why this is not seeing my file in its location because it is there. Iam trying to import all .txt files in one folder and then archive in a seperate folder. I am not an expert by any means.. know enough to be dangerous..

    Code:
    Private Sub ImportFiles_Click()
        Dim RSO As Object
        Dim strFolderPath As String
        Dim strFile As String
        Set RSO = CreateObject("Scripting.FileSystemObject")
    
        strFolderPath = "C:\SFOEDL\TL"
      
       strFile = Dir(strFolderPath & "\*.txt", vbNormal)
        Do While strFile <> ""
            If strFile > " " Then
            
            DoCmd.TransferText acImportFixed, "TLimport", "TblTL", strFile, False
            Name strFolderPath & strFile As "C:\SFOEDL\TL\Archive"
            End If
            
            strFile = Dir()
         Loop
        
    End Sub
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    You do not need the Reference to the Microsoft Scripting Runtime Object Library. The basic, and simplest, syntax for referencing all Text Files in a given Folder would be:
    Code:
    Dim strFolderPath As String
    Dim strFile As String
      
    strFolderPath = "C:\SFOEDL\TL"
      
    strFile = Dir(strFolderPath & "\*.txt", vbNormal)
    
    Do While strFile <> ""
      Debug.Print strFile
        strFile = Dir()
    Loop

    Comment

    • Wayne L
      New Member
      • Sep 2007
      • 31

      #3
      Found out what was missing..
      DoCmd.TransferT ext acImportFixed, "TLimport", "TblTL", strFolderPath & strFile,
      I needed to add the folder path and the file together..
      Attached code is what worked. Thanks for the assist!!!

      Code:
      Dim strFolderPath As String
      Dim strFile As String
        
      strFolderPath = "C:\SFOEDL\TL\"
        
      strFile = Dir(strFolderPath & "\*.txt", vbNormal)
      
      Do While strFile <> ""
      If strFile <> "." And strFile <> ".." Then
        Debug.Print strFile
          strFile = Dir()
          DoCmd.TransferText acImportFixed, "TLimport", "TblTL", strFolderPath & strFile, False
          End If
      Loop
      Last edited by Wayne L; Nov 16 '10, 06:41 PM. Reason: figured out the problem

      Comment

      Working...