Results 1 to 4 of 4
  1. #1
    PJ Crittenden is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    22

    How do I Save/Import .txt file name to Access when importing?

    I'm loading one file at a time and I need to also save the file name to the database. How do I do that?

    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    If you are running transfertextfile, and you have the SPECname defined in import specifications,
    Link the text file as a table, then import that table to an internal table.

    In the code:

    Code:
    vFile = txtFilePath
    
      'link the file as a table
    DoCmd.TransferText acLinkDelim, SPECname, "txtTable2Import", vFile, True
    
       'run the append query to put the text file data into a table.  IN THE QUERY HAVE A FIELD THAT WRITES THE FILE PATH from the txtBox.
      'as  forms!frmImport!txtFilePath
    
       'append data
    docmd.openquery "qaAppendData"

  3. #3
    PJ Crittenden is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    22
    I am not using the import wizard. There is a reason I have to process one file at a time... So, there is ONE file in a folder on a network drive. I have to change the name of that file in order to process it, but BEFORE I change it, I want to save the ORIGINAL file name to a table in Access.

    Could you please help me with that?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You HAVE to process 1 file at a time. No other way.

    You do NOT have to change the name of the file to process it.
    1. Put the filename in the text box,
    2. the DoCmd.TransferText LINE PUTS THE PICKED FILE AS txtTable2Import TABLE. (but I didnt give you the delete line), so...


    Code:
    const  kTMPtbl =  "txtTable2Import"
    dim vFile
    
    vFile = txtFilePath
       'delete the previous table
    CurrentDb.TableDefs.Delete kTMPtbl 
    
      'link the file as a table
    DoCmd.TransferText acLinkDelim, SPECname, kTMPtbl, vFile, True
       'run the append query to put the text file data into a table.  IN THE QUERY HAVE A FIELD THAT WRITES THE FILE PATH from the txtBox.
       'as  FILENAME: forms!frmImport!txtFilePath
    
       'append data
    docmd.openquery "qaAppendData"
    Last edited by ranman256; 11-05-2014 at 12:23 PM.

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

Similar Threads

  1. Import spec for importing Excel2010 into Access 2010
    By crowegreg in forum Import/Export Data
    Replies: 0
    Last Post: 08-02-2013, 12:18 PM
  2. Importing Excel File - Getting 7 extra blank rows each import
    By eking002 in forum Import/Export Data
    Replies: 4
    Last Post: 06-13-2013, 09:15 AM
  3. Importing CSV file into 2010/creating save import routine
    By rbtrout in forum Import/Export Data
    Replies: 5
    Last Post: 08-05-2011, 08:54 AM
  4. Importing Excel file. (2 non numeric values won't import)
    By Amerigo in forum Import/Export Data
    Replies: 3
    Last Post: 05-20-2011, 11:31 AM
  5. Importing Txt file to Access
    By fuxy in forum Access
    Replies: 6
    Last Post: 04-25-2011, 07:58 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