Solved

Repated data import - MS Access

Posted on 2011-03-09
5
281 Views
Last Modified: 2012-05-11
Hello,

I previously asked a question about importing data from a csv to MS Access, found here:  http://www.experts-exchange.com/Database/Miscellaneous/Q_26781566.html

During this thread, someone asked me if this would be a one time thing, or repeated.
To which I answered, one time - but I've found out since then that it will be a repeated action after all.

Someone suggested using: DoCmd.TransferText transfertype:=acImportDelim, _
      tablename:="tblMonthlyData", _
      FileName:="D:\Documents\Examples\Monthly Data.csv", _
      hasfieldnames:=False

But I would like a step-by-step procedure as to how to do this if possible.
(Screenshots would help please)

Thank you
0
Comment
Question by:--TripWire--
  • 3
  • 2
5 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 350 total points
ID: 35085784
The code that you reference is just a single line of code. YOu could "call" that code in the Click event of your button, for example, or during some other "event".

As to step-by-step, that would depend on exactly when you need to do this (i.e what Event you would use), but if you're going to use a Button:

1) Add a button to your form (name it "cmImport")
2) In Properties dialog for the button, select the Event tab
3) Locate the "Click" event, and select "[Event Procedure]" in the dropdown next to it
4) Click the build button to the right of that dropdown

This will throw you into the VBA Editor, and Access will build the Stubs for you. It will look like this:

Sub cmImport_Click()

End Sub

Your code would go between the "Sub" and "End Sub" lines:

Sub cmImport_Click()

 DoCmd.TransferText transfertype:=acImportDelim, _
      tablename:="tblMonthlyData", _
      FileName:="D:\Documents\Examples\Monthly Data.csv", _
      hasfieldnames:=False

End Sub

You would obviously have to change the Tablename and Filename to match your project.
0
 

Author Comment

by:--TripWire--
ID: 35087102
Ok thanks, I want to try that out.  But I only want to import certain data.

For example.  Lets say my Access table has 15 fields, but I only want to import 5 fields from my csv.  How would I go about this?
0
 
LVL 84
ID: 35089119
You can't do so easily, but you can import to a Temporary table, and then use Access methods to move the data from your 5 fields to your "live" Access data. To do that, you'd run code like this AFTER your call to TransferText:

Currentdb.Execute "INSERT INTO YourLiveTable(Col1, Col2, Col3) SELECT Col1, Col2, Col3 FROM YourTemporaryTable"

Obviously you'd need to change the Table and Column names to match your project.
0
 

Author Comment

by:--TripWire--
ID: 35089151
Ok Thanks.  Is that run in a Macro as well?
Will the auto-number PK I have in my table populate by itself when I insert this data?
0
 

Author Comment

by:--TripWire--
ID: 35097339
Thanks for your help.  So far what you've suggested has worked.
Only, I've noticed the newly imported values have appended "3775" to the front of my auto-number field.

For example, my records will auto-number (incrementing by one each time) and then suddenly they'll change when it gets to the new values.

2065, 2068, 37752069, 37752070, 37752071...

Please help
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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 …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now