Sherman6789
Programmer
Hello,
We have an Access table that holds basic information used by most of the people in the office. I'll call this the "#1 - Primary" table.
Information for updating this table is sent to us about every two weeks in the form of an Excel spreadsheet. This is a new Excel file sent each time with a different name. An Access copy of this table is created. I'll call this table the "#2 - Temporary" table.
Last June, I received instructions on how to automatically have a "temporary" Access table created from the Excel Spreadsheet. Field #10 from the temp table is then deleted. The two tables are merged and any new records found on the temporary table are copied into the primary table. All duplicate records are ignored/rejected. Finally, the temporary Access table is deleted. All of this is done at a push of a button.
This has worked well for the past few months until I recently received new instructions. One of the fields on the temporary table needs to be pushed into the primary table each time regardless of whether the record is new or old. This one field is updated constantly and we need the lastest results for this one field to be reflected at all times.
I think that after the new records are merged into the primary table that another command should be added which will match the key field of both table and replace this field in the primary table with that of the temporary table. At that time the temporary table will automatically be deleted.
**************************************************
Here are the basic commands attached to the update button:
Private Sub cmdGetExcelFile_Click()
'Transfer spreadsheet on a: to a new temporary table
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblTempUpdateExcel", "a:\ExcelImport.xls", True
CurrentDb.Execute "ALTER TABLE tblTempUpdateExcel DROP COLUMN F10;"
'Append old Table with data from new table
CurrentDb.Execute "INSERT INTO tblNIDDKGrantApps SELECT tblTempUpdateExcel.* FROM tblTempUpdateExcel;"
' Delete "NewTableName" table after you are satisfied that it is ok.
DoCmd.DeleteObject acTable, "tblTempUpdateExcel"
DoCmd.Close
End Sub
**************************************************
NOTE: Even though the initial Excel spreadsheet has a different name each time, it is copied onto a floppy disk and given a preset name: "ExcelImport.xls". This name and floppy drive are imbedded into the sql statements.
Any suggestions?
We have an Access table that holds basic information used by most of the people in the office. I'll call this the "#1 - Primary" table.
Information for updating this table is sent to us about every two weeks in the form of an Excel spreadsheet. This is a new Excel file sent each time with a different name. An Access copy of this table is created. I'll call this table the "#2 - Temporary" table.
Last June, I received instructions on how to automatically have a "temporary" Access table created from the Excel Spreadsheet. Field #10 from the temp table is then deleted. The two tables are merged and any new records found on the temporary table are copied into the primary table. All duplicate records are ignored/rejected. Finally, the temporary Access table is deleted. All of this is done at a push of a button.
This has worked well for the past few months until I recently received new instructions. One of the fields on the temporary table needs to be pushed into the primary table each time regardless of whether the record is new or old. This one field is updated constantly and we need the lastest results for this one field to be reflected at all times.
I think that after the new records are merged into the primary table that another command should be added which will match the key field of both table and replace this field in the primary table with that of the temporary table. At that time the temporary table will automatically be deleted.
**************************************************
Here are the basic commands attached to the update button:
Private Sub cmdGetExcelFile_Click()
'Transfer spreadsheet on a: to a new temporary table
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblTempUpdateExcel", "a:\ExcelImport.xls", True
CurrentDb.Execute "ALTER TABLE tblTempUpdateExcel DROP COLUMN F10;"
'Append old Table with data from new table
CurrentDb.Execute "INSERT INTO tblNIDDKGrantApps SELECT tblTempUpdateExcel.* FROM tblTempUpdateExcel;"
' Delete "NewTableName" table after you are satisfied that it is ok.
DoCmd.DeleteObject acTable, "tblTempUpdateExcel"
DoCmd.Close
End Sub
**************************************************
NOTE: Even though the initial Excel spreadsheet has a different name each time, it is copied onto a floppy disk and given a preset name: "ExcelImport.xls". This name and floppy drive are imbedded into the sql statements.
Any suggestions?