We help IT Professionals succeed at work.
Get Started

Replace text in a string with a table field value

Last Modified: 2015-03-12
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:
Instr([TableName]![EXPRESSION]) = "@M.PCNT"
strReplace = [MasterTable]![PCNT]
Instr([TableName]![EXPRESSION]) = "@M.DOLLAR"
strReplace = [MasterTable]![DOLLAR]
Have a case for every reference in the expression field.
Example expression:
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!
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE