I have some VBA code that imports data for each table from an excel spreadsheet.
I am trying to do this by looping through table definitions. In this way I don't have to bother if the number of tables changes.
To import I'm running the following.
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable, strFileNameXls, True, ""
This works for most tables but there are a number that fail because of referential integrity because they rely on a table already being processed. If the table they rely on is higher in the alphabet then the load will fail.
I can get round this in a number of ways.
1. Identify those tables that are failing and import them in the right order outside of the loop.
2. Rename some of the tables so they appear in the "correct" alphabetical order.
3. Run through the loop repeatedly until all the imports have been successfully imported - so set up some array with tablenames in keeping track in whether or not the import has worked. If all tables haven't been implemented go through loop again and process only those that have failed.
4. Switch off referential integrity. Loop through the table defs. Switch on data integrity.
Pros and cons are
1. This detracts from the automation I'm after and adding in extra tables could mean extra analysis to where it belongs - ie code needed in the loop not to process and outside of the loop to process.
2. Yeah right
3. Beginning to like this idea if turning referential integrity is a) not possible b) more trouble than it's worth or c) an absolute no no under any circumstance WHATEVER! Besides I can code this now (once I've revised array processing)
4. Don't know if it's possible and if so potentially dangerous
I am trying to do this by looping through table definitions. In this way I don't have to bother if the number of tables changes.
To import I'm running the following.
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable, strFileNameXls, True, ""
This works for most tables but there are a number that fail because of referential integrity because they rely on a table already being processed. If the table they rely on is higher in the alphabet then the load will fail.
I can get round this in a number of ways.
1. Identify those tables that are failing and import them in the right order outside of the loop.
2. Rename some of the tables so they appear in the "correct" alphabetical order.
3. Run through the loop repeatedly until all the imports have been successfully imported - so set up some array with tablenames in keeping track in whether or not the import has worked. If all tables haven't been implemented go through loop again and process only those that have failed.
4. Switch off referential integrity. Loop through the table defs. Switch on data integrity.
Pros and cons are
1. This detracts from the automation I'm after and adding in extra tables could mean extra analysis to where it belongs - ie code needed in the loop not to process and outside of the loop to process.
2. Yeah right
3. Beginning to like this idea if turning referential integrity is a) not possible b) more trouble than it's worth or c) an absolute no no under any circumstance WHATEVER! Besides I can code this now (once I've revised array processing)
4. Don't know if it's possible and if so potentially dangerous