This involves two tables in our Access 2007.
A "Station Master" table consist of records of workstations
A "Move-Add-Change" table consist of records for move, add, change steps for specifics Project Id.
I created a query to pull all records from "Move-Add-Change" that match the a Project Id. Then, I will need to process as follows:
Go thru each row in "Pull MAC Records by Project # Qry"
query (there's a Sequence field
numbering from 1 counting up in there too)
If the Action field in the row is Move:
If the "To Loc" of the same row is not beginning with TSS (used for Inventory Loc), update the records in "Station Master" with the Loc Name equal to the "From Loc" field of the same row in
"Pull MAC Records by Project # Qry"
query, change its value to the To Loc field of the same row in"Pull MAC Records by Project # Qry"
queryIf the "To Loc" of the same row is beginning with TSS, delete the records in "Station Master" that has Loc Name match the "From Loc" of the same row in
"Pull MAC Records by Project # Qry"
query.
If the Action field in the row is Add:
- Create a new record in "Station Master" with Loc Name is the "To Loc" field of the row
If the Action field in the row is Change:
- Do the same as Move plus udpate the Description of "Station Master" using the info from the Notes field of the same row in
"Pull MAC Records by Project # Qry"
query
The code has to go one by one row in "Pull MAC Records by Project # Qry"
because we might move another station into a location that just moved away.
Example partial results from the query:
Project Id Seq Action From Loc To Loc Notes
A123456 1 Move WFC1234 TSSRepair For OEM service
A123456 2 Move WFC9999 WFC1234 Test station
...
If I call a query to do the update, it seems like it doesn't goes thru row by row and would prompt for violation (I think it tried to change WFC9999 to WFC1234 when the original WFC1234 record still there, cause duplicate).
Here is the SQL of my query:
UPDATE [Station Master], [Pull MAC Records by Project # Qry]
SET [Station Master].[Loc Name] = [Pull MAC Records by Project # Qry]![To Loc],
[Station Master].[Loc Function] = Left([Pull MAC Records by Project # Qry]![To Loc],3), [Station Master].[Loc #] = Right([Pull MAC Records by Project # Qry]![To Loc],Len([Pull MAC Records by Project # Qry]![To Loc])-3)
WHERE
((([Station Master].[Loc Name]) = [Pull MAC Records by Project # Qry]![From Loc]));
What did I do wrong? Can I have all those processes purely in VBA code (which I am not good about)?