Solved

Import File into Database With VBA (Indexes and Primary key needed)

Posted on 2001-08-29
7
308 Views
Last Modified: 2012-05-04
I have to import a CSV file into a NEW table.
WITH INDEXES ON THE 2 FIRST FIELDS + AUTONUMBER PRIMARY KEY

Structure:
"BBC PRDB","BBC APOLLO","BBC0011 - ZPRDB ORDERS","75","1000"," "," ","22/06/01","094637","000000","22/06/01","094644","0.13","BBC MEDAS","BBC APOLLO BILLING","FTP OTHER STOCKLEY","ECSD-MEDIS","N","22-JUN-2001 9:46:37","186","627","83","169","931108500","13","12"

If I do this with File, Get External Data, Import, and follow the complete wizard.
Everything is imported OK!

TABLE STUCTURE BECOMES THEN
ID        Autonumber Primary Key Indexed No Duplicates
Sender    Text 255 Indexed (Duplicates OK)
Receiver  Text 255 Indexed (Duplicates OK)
...

If I save this file specification (File - Get External Data, Import, Advanced, Create a Spec and Save AS) to be able to use the VBA language to import:
DoCmd.TransferText acImportDelim, "MS Billing Import Specification", _
    "IQ RAW DATA", txtIQBillingFilePath.Value, False
The data is imported OK, but there are NO indexes on sender and receiver.

TABLE STUCTURE BECOMES THEN
ID        Autonumber Primary Key Indexed No Duplicates
Sender    Text 255 Indexed No
Receiver  Text 255 Indexed No

In the import specification I HAVE INDICATED that I want indexes on those 2 fields, but there are none.

Access Version is 97 sr2

Anyone knows why this happens and can think of a solution?

Thanks T
0
Comment
Question by:thimerion
  • 4
  • 2
7 Comments
 
LVL 54

Accepted Solution

by:
nico5038 earned 200 total points
ID: 6437097
You could add the indexes "manually" by using:

currentdb.execute("CREATE INDEX .......;")

Just check the helpfile for the exact syntax.

Nic;o)
0
 
LVL 6

Expert Comment

by:xSinbad
ID: 6439223
For MS help (as nico said)

The next example creates an index consisting of the fields HomePhone and Extension in the Employees table:

CREATE INDEX NewIndex ON Employees (HomePhone, Extension);
0
 
LVL 1

Author Comment

by:thimerion
ID: 6445089
OK Thanks for your help!
I use now the code:
DoCmd.TransferText acImportDelim, "MS Billing Import Specification", _
    "MsRawData", txtMSBillingFilePath.Value, False
CurrentDb.Execute "CREATE INDEX MSRD_Sender_idx ON MsRawData (Sender);"
CurrentDb.Execute "CREATE INDEX MSRD_Receiver_idx ON MsRawData (Receiver);"
CurrentDb.Execute "CREATE INDEX MSRD_Customer_idx ON MsRawData (Customer);"
CurrentDb.Execute "CREATE INDEX MSRD_DateAndTime_idx ON MsRawData (DateAndTime);"

To get the desired result.

However I have my doubts on the performance of this solution, as it takes quite a while to create indexes on the existing data.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:thimerion
ID: 6445104
Thanks!
But if you can find a more performant (quicker) way to import a 20Mb text file and add indexes, I'd be happy to hear it.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 6445114
The creation of an index always asks time, as Access will have to build a file having all key's in it.
It's only necessary to build indexes when the appication is also using them.
To detect this you'll need to check the execution plans of the queries.

Personally I always start without extra indexes and when performance is growing bad, I'll add them.

Nic;o)
0
 
LVL 1

Author Comment

by:thimerion
ID: 6445165
I am definately using those indexes;
I run about 40 queries on that table with those indexed fields in the WHERE clause.

I was just wondering:

What is the most performant solution?
1*/Create empty table WITH indexes,
then add the data.
2*/Add the data, then create indexes.

Why is the import specification not doing it's work correctly?
0
 
LVL 1

Author Comment

by:thimerion
ID: 6445304
I just tested it myself...

Insert the data first,
then create the indexes takes access 1'20''

Create a table with indexes,
then insert the data takes access 1'35''

Anyway thanks again Nico
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

746 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

9 Experts available now in Live!

Get 1:1 Help Now