Replace text in a string with a table field value

I’m using an Access database. One of the tables contains a field that is a string expression. The string expression contains a reference to a field in another MASTER table in the database.
The Master table is joined by ID# with the table with the string expression (INNER JOIN MasteTable ON TableName.IDNUM = MasterTable.IDNUM

Example expression:
@M.PCNT @M.DOLLAR 0 % M$  
(PCNT & DOLLAR are fields in a MASTER table)
I would like to replace the reference with the actual value in the field it is referencing. When there is only one reference, I have designed a query and used:
EXPRESSION2: Replace([TableName]![EXPRESSION],"@M.PCNT",[MasterTable]![PCNT])
But, when there is more than one reference in the expression string, I have not found a syntax that will replace more than one reference.
I was thinking that a function that would check the case and make the appropriate replacement for the entire table instead of making separate querries would be nice, but I’m not sure of the syntax.
Like what I had in mind:
Case
Instr([TableName]![EXPRESSION]) = "@M.PCNT"
strReplace = [MasterTable]![PCNT]
Case
Instr([TableName]![EXPRESSION]) = "@M.DOLLAR"
strReplace = [MasterTable]![DOLLAR]
Have a case for every reference in the expression field.
Example expression:
@M.PCNT @M.DOLLAR 0 % M$
The Result would be like this
.02 500 0 % M$
if (@M.PCNT field value = .02) and (@M.DOLLAR field value = 500)
But the tables would have to be joined by ID#

Any help would be greatly appreciated!
ktjamms2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tbsgadiCommented:
Try: Replace(Replace([TableName]![EXPRESSION],"@M.PCNT",[MasterTable]![PCNT]),[TableName]![EXPRESSION],"@M.DOLLAR",[MasterTable]![DOLLAR])
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
als315Commented:
You can add small table  with two fields: source and replacement. In first record should be @M.DOLLAR and 500, in second @M.PCNT and .02
Then create an update query
Look at sample (tbl11- source, tbl2- replacement rules, qry1- update query)
DB1.accdb
0
ktjamms2Author Commented:
tbsgadi, I tried yours:
Try: Replace(Replace([TableName]![EXPRESSION],"@M.PCNT",[MasterTable]![PCNT]),[TableName]![EXPRESSION],"@M.DOLLAR",[MasterTable]![DOLLAR])

I don't know if I'm doing something wrong, but in the cases where the same reference is in the expression more than once, it returns #Error and for the rest, it returns only the REFERENCE (@M.DOLLAR) OR it returns #Func! and not the remainder of the string expression.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ktjamms2Author Commented:
There are too many records to try to re-create two tables every time I need to complete this task.
0
als315Commented:
You need only records with values to be replaced. Have you looked sample DB?
0
ktjamms2Author Commented:
Each ID# can have 50 records with different references to the master table and I have about 23,000 ID#'s. Total of about 600,000 lines that need references replaced with an estimated 75 fields from the master table. Some strings reference more than one master table field.
0
ktjamms2Author Commented:
The references don't have the same values for each ID#
0
ktjamms2Author Commented:
This Works...had to remove the [TableName]![EXPRESSION],

Replace(Replace([TableName]![EXPRESSION],"@M.PCNT",[MasterTable]![PCNT]),"@M.DOLLAR",[MasterTable]![DOLLAR])
0
tbsgadiCommented:
Great! Glad to help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.