S
Santa-D
I'll try to simplify this so it's easy to follow and understand.
I have a table [MAIN] that contains a large amount of data related to
various assets.
I receive an excel sheet from the supplier which I use to manage these
assets.
Currently I have a macro with VBA and a delete records query to copy
and paste the [MAIN] table into another MDB and append the date it was
copied. Delete all the records and import the spreadsheet into the
existing [MAIN] table.
What I want to do is the following:
* UPDATE records currently in [MAIN] with records in [MAIN_TEMP] which
is the import from excel
* APPEND records not found in [MAIN] but found in [MAIN_TEMP] and
* UPDATE [MAIN].[STATUS] to "9" where [MAIN].[ORDNO] <>
[MAIN_TEMP].[ORDNO]
[ORDNO] is the primary key
This is the VBA function to copy & paste the table into another MDB
file (backup)
------------------------------------------------------------------------------------------------------------------------------------------
Function veh_exporttable_Main()
DoCmd.SetWarnings WarningsOff
Dim desttable_main As String
desttable_main = "x - " & Format(Now(), "dd-mm-yy") & " - Old-Main"
DoCmd.CopyObject "V:\Data Sources\DoJ Fleet Management - Archives.mdb",
desttable_main, acTable, "MAIN"
DoCmd.SetWarnings WarningsOn
End Function
------------------------------------------------------------------------------------------------------------------------------------------
This is what I've got in the macro to import the data.
Set Warnings - No
RunCode - veh_exporttable_Main ()
OpenQuery - delete-all-records | Viewatasheet | Data Mode:Read Only
TransferSpreadsheet - Import | Type:Excel 8-10 | TableName:MAIN |
FileName:<path to file> | HasFieldNames:Yes | Range:
Set Warnings - Yes
------------------------------------------------------------------------------------------------------------------------------------------
I've created an update & an append query but I'm not sure if it'll work
as when I try to run the "update status 9" query and press run I get 0
records even tho I've added some dummy data so I know it won't join.
UPDATE MAIN INNER JOIN MAIN_TEMP ON MAIN.ORDNO = MAIN_TEMP.ORDNO SET
MAIN.[Reorder Status] = "9", MAIN.[Date Status Changed] = Date()
WHERE (((MAIN.ORDNO)<>[MAIN_TEMP].[ORDNO]));
I have a table [MAIN] that contains a large amount of data related to
various assets.
I receive an excel sheet from the supplier which I use to manage these
assets.
Currently I have a macro with VBA and a delete records query to copy
and paste the [MAIN] table into another MDB and append the date it was
copied. Delete all the records and import the spreadsheet into the
existing [MAIN] table.
What I want to do is the following:
* UPDATE records currently in [MAIN] with records in [MAIN_TEMP] which
is the import from excel
* APPEND records not found in [MAIN] but found in [MAIN_TEMP] and
* UPDATE [MAIN].[STATUS] to "9" where [MAIN].[ORDNO] <>
[MAIN_TEMP].[ORDNO]
[ORDNO] is the primary key
This is the VBA function to copy & paste the table into another MDB
file (backup)
------------------------------------------------------------------------------------------------------------------------------------------
Function veh_exporttable_Main()
DoCmd.SetWarnings WarningsOff
Dim desttable_main As String
desttable_main = "x - " & Format(Now(), "dd-mm-yy") & " - Old-Main"
DoCmd.CopyObject "V:\Data Sources\DoJ Fleet Management - Archives.mdb",
desttable_main, acTable, "MAIN"
DoCmd.SetWarnings WarningsOn
End Function
------------------------------------------------------------------------------------------------------------------------------------------
This is what I've got in the macro to import the data.
Set Warnings - No
RunCode - veh_exporttable_Main ()
OpenQuery - delete-all-records | Viewatasheet | Data Mode:Read Only
TransferSpreadsheet - Import | Type:Excel 8-10 | TableName:MAIN |
FileName:<path to file> | HasFieldNames:Yes | Range:
Set Warnings - Yes
------------------------------------------------------------------------------------------------------------------------------------------
I've created an update & an append query but I'm not sure if it'll work
as when I try to run the "update status 9" query and press run I get 0
records even tho I've added some dummy data so I know it won't join.
UPDATE MAIN INNER JOIN MAIN_TEMP ON MAIN.ORDNO = MAIN_TEMP.ORDNO SET
MAIN.[Reorder Status] = "9", MAIN.[Date Status Changed] = Date()
WHERE (((MAIN.ORDNO)<>[MAIN_TEMP].[ORDNO]));