Results 1 to 7 of 7
  1. #1
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596

    Open Text file using only the first 7 characters of the file name.

    I need to open and process the data from a text file on the network.


    The first 7 characters of the file name will be the same every day.
    The rest of the file name will change from day to day.
    There will only be one file in the folder that has those first 7 characters.
    There are a total of about 120 text files in the folder every day - give or take - including the one I need to open and read.

    I would appreciate some vba help with this.

    Thanks!!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Options:

    1. manually import the data with Import/Export wizard

    2. programatically set a link to the file and then it is available for manipulation like a table

    3. programatically open the file as an object in VBA and read each line and parse the data into a recordset of the destination table


    Is this a new folder each day? Or are the files replaced every day?
    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
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Hi June!
    There is a new folder each day - but that is not part of what need help with.
    I am used to opening text files and doing whatever I need to with the text in them etc.
    What I need help with is VBA code for opening a file that I only have the first 7 characters of the file name for.
    Eg: The File Name might be "ABCDEF_12345" today and "ABCDEF_s8m39kdm65" tomorrow. The "ABCDEF_" will always be the same . . . the rest of the file name is not predictable.
    I wonder if I've explained well enough.

    I suspect I will have to do something like:
    Dim strFileName as String
    strFileName = "ABCDEF_" & "*" & ".txt"
    and then use a Dir statement to search through the folder in question for the one file that meets that criterion . . .
    This VBA is what I need help with.
    Thanks!
    Robeen

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Have you tried strFileName = "ABCDEF_" & "*" & ".txt" yet? If this does not provide the desired results, you may have to enumerate all of the .txt files first. Then go through your now known .txt files and find the appropriate names.

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Every file in that folder will always be a .txt file.
    I will try the 'strFileName . . .' deal and see if I can get it working.
    I am just not sure of how to use the Dir statement to complete the logic . . .

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    If all files in the folder are of type .txt then

    strFileName = "ABCDEF_*"

    should suffice

    I just can't recall how I have dealt with these issues before.... just working from memory here.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Since the 7 characters are known and will be in only one file name in the folder, that's easy part. However, if there is a new folder each day, is the new folder name known?
    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. Replies: 3
    Last Post: 02-22-2013, 06:41 AM
  2. Replies: 2
    Last Post: 12-27-2012, 09:37 AM
  3. Replies: 3
    Last Post: 07-30-2012, 02:16 PM
  4. Replies: 1
    Last Post: 09-27-2010, 10:10 AM
  5. Open a text file to show results...
    By kkrishna in forum Programming
    Replies: 3
    Last Post: 08-13-2010, 09:38 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