I have been importing data from a CRM database into Access to run some more complex reports than the CRM database will allow - The problem is that I don't want to import ALL of the data each week, only that data that has changed.
The export feature of the CRM allows me to do this.
However, I need to figure out the best way of updating my access tables. I am thinking that I need to create a new table with the updated data that I am importing and then append my old tables to the new data. I have a primary field that I will use as the primary key.
If I don't do it this way, it won't overwrite my new data due to conflicts with the primary key.
That being said, how do I change a field to the primary key via VBA?
This is what I have so far:
'rename current tables
DoCmd.Rename "Accounts", acTable, "AccountsOLD"
DoCmd.Rename "Opportunities", acTable, "OpportunitiesOLD"
DoCmd.Rename "Opportunity Products", acTable, "OpportunityProductsOLD"
'Import new files from 'Siebel Import Files' folder
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Accounts", _
"C:\Documents and Settings\fkampf\My Documents\Siebel Database\Siebel Import Files\Accounts.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Opportunities", _
"C:\Documents and Settings\fkampf\My Documents\Siebel Database\Siebel Import Files\Opportunities.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Opportunity Products", _
"C:\Documents and Settings\fkampf\My Documents\Siebel Database\Siebel Import Files\Opportunity Products.xls", True
'delete current tables (old data)
DoCmd.DeleteObject acTable, "AccountsOLD"
DoCmd.DeleteObject acTable, "OpportunitiesOLD"
DoCmd.DeleteObject acTable, "Opportunity ProductsOLD"
MsgBox "DONE!"
Any help would be appreciated!!! thanks!!! Fred
The export feature of the CRM allows me to do this.
However, I need to figure out the best way of updating my access tables. I am thinking that I need to create a new table with the updated data that I am importing and then append my old tables to the new data. I have a primary field that I will use as the primary key.
If I don't do it this way, it won't overwrite my new data due to conflicts with the primary key.
That being said, how do I change a field to the primary key via VBA?
This is what I have so far:
'rename current tables
DoCmd.Rename "Accounts", acTable, "AccountsOLD"
DoCmd.Rename "Opportunities", acTable, "OpportunitiesOLD"
DoCmd.Rename "Opportunity Products", acTable, "OpportunityProductsOLD"
'Import new files from 'Siebel Import Files' folder
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Accounts", _
"C:\Documents and Settings\fkampf\My Documents\Siebel Database\Siebel Import Files\Accounts.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Opportunities", _
"C:\Documents and Settings\fkampf\My Documents\Siebel Database\Siebel Import Files\Opportunities.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Opportunity Products", _
"C:\Documents and Settings\fkampf\My Documents\Siebel Database\Siebel Import Files\Opportunity Products.xls", True
'delete current tables (old data)
DoCmd.DeleteObject acTable, "AccountsOLD"
DoCmd.DeleteObject acTable, "OpportunitiesOLD"
DoCmd.DeleteObject acTable, "Opportunity ProductsOLD"
MsgBox "DONE!"
Any help would be appreciated!!! thanks!!! Fred