I'm working on a database that includes two different tables that need records matched and updated. Basically if two string fields are equal to each other, update a different field.
I can't quite figure it all out.
The first table, IngredientDB
, includes two string fields, Item Number
and Ingredient Name
The second table, Table Material Label
, also includes two string fields, MaterialCode
and MaterialDescription
Ingredient Name
and MaterialDescription
has a lot of the same records, but not all of them are the same.
I want to be able to
- match
MaterialDescription
andIngredient Name
- update the
MaterialCode
to be the exact same as the item number that corresponds to thatIngredient Name
.
So I tried using a update query and an if statement, this is what it looked like:
- Field: MaterialCode
- Table: Table Material Label
- Update To: iif([MaterialDescription]=[Ingredient Name],[Item Number],"NotFound")
- Criteria: BLANK
- or: BLANK
The current issue is that all of the MaterialCode
records get filled with "Not Found", meaning its not finding any matches for some reason...
Is there an easier way to do all of this? Am I missing something? Sorry I'm kind of a novice when it comes to Access stuff. Still learning!
Edit: Here is an image of where I'm currently at. The arrows indicate what I'm trying to change.
Code from image, currently getting syntax error
UPDATE [Table Material Label] JOIN [IngredientsDB] on [Table Material Label.MaterialDescription] = [IngredientsDB.Item Number]
SET [MaterialCode] = [Item Number]
WHERE [MaterialDescription] = [Ingredient Name]