Solved

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

Posted on 2001-08-29
7
314 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

840 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