
Originally Posted by
ItsMe
Linking an Excel file to an Access file will cause the Excel file to be read only while the Access file is open. Using the Wizard to create and save an import procedure may be an option. You could bring the daily Excel file into a temp table and then run your update query. Afterwards, delete all of the records in your temp table.
I'm leaning towards the Temporary "Import Table" then updating the main from that. From other sources I have mashed together this example code which seems to work in the simplified basic example I set up:
Code:
Sub test()
Dim strSQL As String
strSQL = "UPDATE tbl_Main LEFT JOIN tbl_Import_TEMP ON tbl_Main.HB = tbl_Import_TEMP.HB SET tbl_Main.Status = tbl_Import_TEMP.Status WHERE tbl_Import_TEMP.Status<>tbl_Main.Status"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
strSQL = "INSERT INTO tbl_Main ( HB, Status, ETA) SELECT tbl_Import_TEMP.HB, tbl_Import_TEMP.Status, tbl_Import_TEMP.ETA FROM tbl_Import_TEMP"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End Sub
This first run updates the Main table, the second run adds in new records I believe.
I'm still don't totally understand what they are doing however. Like the update one (first .RunSQL) that only updates one field "Status", but in the real database it would need to update at least 5 or 6 different fields potentially.
Also the second add records run, the Import Temp table will only have like 6 fields (with basic information for each record), but the Main table will have those fields, plus like 6 yes/no fields so users can tick off tasks they have performed. I dont know if the second run does default No values or what?
And ideally, during the updating, I would like a changes table to record the following field each time a change occurs: "ID (only cause I need a unique key)" "HB" "Field Name (so "Status" "ETA" "Finished" etc) "Old Value" "New Value" "Username" "TimeStamp"
So for example if HB 55 have an ETA of 29/04/14, and an update changes that to 30/04/14 then the changes table will have a record like:
ID |
HB |
FieldName |
OldValue |
NewValue |
UserName |
TimeStamp |
1 |
55 |
ETA |
29/04/14 |
30/04/14 |
tbaker |
29/04/14 10.35 AM |
|
|
|
|
|
|
|
Does that make sense? So I can see from that record, that the ETA field of HB 55 was changed from 29/04/14 to 30/04/14 by myself at 10.35am on the 29th. Obviously there will be lots of field names.