+ Reply to Thread
Results 1 to 5 of 5

VBA to Import data into Access 03

Hybrid View

pdauction VBA to Import data into... 10-14-2010, 07:08 AM
split_atom18 Re: VBA to Import data into... 10-20-2010, 10:59 AM
pdauction Re: VBA to Import data into... 10-21-2010, 10:53 AM
split_atom18 Re: VBA to Import data into... 10-21-2010, 03:07 PM
pdauction Re: VBA to Import data into... 11-17-2010, 05:51 AM
  1. #1
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    VBA to Import data into Access 03

    I currently have a process where I import around 10 .txt files into a database each week replacing exisitng ones. Each has it's own specification and 2 have primary keys. I decided to automatically do this using a macro. Code I am using is below...

    DoCmd.DeleteObject acTable, "Agency"
    DoCmd.TransferText acImportDelim, "Agency Import Specification", _
    "Agency", "U:\AS\MIdata\Database\agency.txt"

    DoCmd.OpenQuery ("Agency_Prim_Key")
    The SQL for the above is below
    ALTER TABLE Agency
    ADD PRIMARY KEY (uan);

    Problems Encountered...
    • When doing this process manually I just import and it over-writes the existing table but when I use the VBA method it seems to append for some reason. I have therefore added code to delete the original.
    • The second and main problem is that after importing it comes up with creating and changing indexes which not only takes time but is not something I do not want to happen and doesn't happen when doing manually presumably because I am choosing a primary key (or not in other circumstances) in the import wizard.

    Does anyone know a way to import without Access adding its own Indexes (I am not sure the knock on effect of indexes on a table if I am ignorantly honest) but I know it adds time to the macro. Similarlly does anyone know why it appends rather than replacing? As always your help is appreciated.
    Thanks

  2. #2
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: VBA to Import data into Access 03

    At this point I am gonna ask the WHY? question.

    What are your advantages of importing the text file weekly vs linking it with ADO activeconnection?

    What are you doing with the data once it is in the database?

    These are some questions I hope will help me give you a direction to head.

    Thanks,

    Dan
    "I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
    If my advice has been helpful to you, then please help me by clicking on the "Star" and adding to my reputation, Thanks!

  3. #3
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    Re: VBA to Import data into Access 03

    Thanks for responding,

    The text files are downloaded each week after running a SAS program. From there I transfer them into a Database and from there a multitude of differrent queries are run to produce reports (usually through excel) all based on the latest tables imported.

    I currently import the tables as I was unaware of any other way to effectively do this (I didn't use "Link Tables") for a number of reasons.

    I was not aware of using ADO connections and after using the relevant help files and Google I'm still not 100% of the benefits of these or indeed the exact coding I would need to use this connection type - Access is not my forte.

    Cheers
    Paul

  4. #4
    Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    270

    Re: VBA to Import data into Access 03

    So are the tables you download and import new each time like Sales?

    A bit about Indexing: Click here

    If this is going to be a continually growing database as data is added once a week. It would be beneficial to take the little extra time to setup indexing.

    For me personally if I had something like this:
    I would use a Linked File and run my downloads(ie update the linked file)
    Write VBA to copy the Linked File into a Table(with Indexes already setup) with an extra field for the date I imported it.
    Create my reports based on that table. Have a button that I would use annually to clean up that file. Ie. Create a history table for each year - this would allow me to re-create any report I had ever made in a few clicks.

    Hope this helps,

    Dan

  5. #5
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    Re: VBA to Import data into Access 03

    I think you have given me enough to gop on with this, so can be marked as SOLVED.

    Many Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1