Solved

Import Text file into MS Access 2007

Posted on 2014-11-27
5
191 Views
Last Modified: 2014-11-30
I have a text file (.txt) which has thousands of lines with the following format:

aaaaaaa-bbbb;CCCCCCCC;DDDD

each position represents customer_number;customer_name;project_name in the database respectively.  Please note there is no field heading in the text file

MS Access 2007 database has a table name "customer" which has the fields as follows:

customer_number,customer_name,project_name respectively.


I should be grateful if someone could help me providing a VB script or a batch file to run an import of the data in the text file into MS Access 2007.  Thank you.
0
Comment
Question by:yimsoin57
  • 2
  • 2
5 Comments
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40470038
Just run the import wizard at menu External Data. Choose to link the data, not import.
In this, select the separator as semicolon.

Then create a simple append query that uses the linked data as source and your Customer table as target.

/gustav
0
 

Author Comment

by:yimsoin57
ID: 40470061
Actually my text file gets updated twice a day which I do not know which lines are updated.  I need the data be imported into the data and replace the old data not append.
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40470063
Well, then you would use an update query rather than an append query.

/gustav
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40470640
Some of it can be coded.
As /gustav  suggests, create a linked table.
I do this with CSV files all the time.

Then for code
'kill everything in Customer
DoCmd.SetWarnings False
CurrentDb.Execute "DELETE Customer.* FROM Customer;", dbSeeChanges
DoCmd.SetWarnings True
'Insert everything from the linked CSV into Customer
'code for the insert here

Open in new window


Now, if you have created the linked table as /gustav has suggested, tell us the name of the new linked table and perhaps /gustav would be so kind as to supply the insert part of the SQL code (I always use recordset code, which wouldn't be efficient for a bulk insert like this)
0
 

Author Closing Comment

by:yimsoin57
ID: 40473170
Everything is perfectly done as advised.  Thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question