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?
 
tbsgadiCommented:
Try: Replace(Replace([TableName]![EXPRESSION],"@M.PCNT",[MasterTable]![PCNT]),[TableName]![EXPRESSION],"@M.DOLLAR",[MasterTable]![DOLLAR])
0
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.