Results 1 to 4 of 4
  1. #1
    Skybeau73599 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    1

    Recordset importing from second entry, not the first

    I use the below code to cycle through entries in a table and import the corresponding CSV file into my Temp table in a database. The issue I'm having is that it starts with record number 2, instead of the first record.

    My fields in the db are Path (eg C:\Form Downloader\25102015\ALFIE'S ROSE.csv) and FileName (eg ALFIE'S ROSE). Can anyone see where I'm going wrong? It also seems to be skipping records and not importing them as well.

    Code:
    Option Compare Database
    
    Sub Import_Data_ListNamesA()
    
    
    DoCmd.SetWarnings False
      
    Dim d As DAO.Database
    Dim r As DAO.Recordset
    Dim intI As Integer
    Dim LstFileNamesA As Field, Path As Field, FileName As Field
    Set d = CurrentDb()
    Set r = d.OpenRecordset("LstFileNamesA")
    Set DogForm = r.Fields("Path")
    Set DelErrorTable = r.Fields("FileName")
     
        While Not r.EOF
          
            DoCmd.SetWarnings False
            DoCmd.TransferText TransferType:=acDelim, TableName:="tbl_TEMP_A", FileName:=DogForm, HasFieldNames:=True
            On Error Resume Next
            DoCmd.DeleteObject acTable, DelErrorTable & "_ImportErrors"
            Err.Clear
            DoCmd.SetWarnings True
            r.MoveNext
            
        Wend
          
    r.Close
    
    
    DoCmd.SetWarnings True
    
    
    MsgBox "Complete"
    
    
    End Sub

    Last edited by Skybeau73599; 10-25-2015 at 03:44 AM. Reason: Adding more information

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you have hasfieldnames=true - perhaps you don't have fieldnames in your file

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your While-Wend loop doesn't look right - it is doing the exact same thing each time through - same table name, same file name. Surely you want to put the Set Dogform line inside the loop, so you use a different file each time.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I don't see where DogForm is Dimmed --but I note you don't have Option Explicit turned on.

    To check your loop, comment out the transfertext lines, use a message or debug.print something to ensure you are actually looping. That is, get the loop logic working before "doing the entire process".
    For your own benefit, break the task into steps; test the steps--
    Good luck

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

Similar Threads

  1. Replies: 5
    Last Post: 03-09-2014, 07:16 PM
  2. Replies: 6
    Last Post: 12-03-2013, 11:14 PM
  3. Replies: 0
    Last Post: 03-12-2012, 03:57 PM
  4. Replies: 2
    Last Post: 03-08-2012, 12:59 PM
  5. Replies: 1
    Last Post: 11-13-2009, 03:03 AM

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