• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 36
  • Last Modified:

batch import data from txt to a MS Access 2007 field

I have a MS Access 2007 database with a list of thousands of people, that includes their id number, name, status, link to photo file location, etc.  I took a couple hundred pictures that had to wait to be entered into the "photo" field, because I had no id numbers for them at the moment.  Now, I do have a txt file with a list of a couple hundred files that are named after their id numbers.  It looks like this:


What I want to do is follow a few steps in Access 2007 (compacted into a macro or a couple of functions) that would:

1. read the txt file
2. find an entry for each id number listed, by taking, say, 007733 out of 007733.jpg and looking it up in the "idnumber" column
3. update those couple hundreds of entries so that, for instance, an entry with 007733 in the "idnumber" column it would have: N:\photos\007733.jpg in the "photo column

You suggestions are most welcome!
1 Solution
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Is this a one time thing? Sounds like it, and if so then first import the Text file into Access using the Get External Data tab. When you do that, you should have a single column table. Now add a second column to that table named "IDNumber", and run this code:

CurrentDb.Execute "update YourTable set IDNumber=Left(YourTextField, Len(YourTextField)-4)"

You can run this from the Immediate window, of from the click event of a button, etc. You'd obviously have to change the Table and Field names to match your own.

Now update your "live" table to show the Photo field:

Currentdb.Execute "UPDATE YourLiveTable SET YourImageField='F:\Photos\" & YourImportTable.ImageName & "'"

You can do most this in the query interface as well - just import the table, and run the first code above in the Immediate window, then create a new query with your two tables, and "join" them on the IDNumber field, and the "ID" field of your existing table. Then select to create an Update query, and add this expression to the Criteria row of the YourImageField column:

"F:|Photos\" & [YourImportTable].FirstTextField
lolekbolekAuthor Commented:
Thank you, Scott.  I usually never have to work with Access, so if you could give me an idea of what the "immediate window" means or how to run your code from it (i.e., what menu options or toolbar buttons to use before getting to a place where I can paste the code), that would be peachy.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Scott McDaniel (Microsoft Access MVP - EE MVE ) (http:#a40200809)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now