ktjamms2
asked on
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]![EXPRE SSION],"@M .PCNT",[Ma sterTable] ![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]![EXPRESS ION]) = "@M.PCNT"
strReplace = [MasterTable]![PCNT]
Case
Instr([TableName]![EXPRESS ION]) = "@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!
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]![EXPRE
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]![EXPRESS
strReplace = [MasterTable]![PCNT]
Case
Instr([TableName]![EXPRESS
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tbsgadi, I tried yours:
Try: Replace(Replace([TableName ]![EXPRESS ION],"@M.P CNT",[Mast erTable]![ PCNT]),[Ta bleName]![ EXPRESSION ],"@M.DOLL AR",[Maste rTable]![D OLLAR])
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.
Try: Replace(Replace([TableName
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.
ASKER
There are too many records to try to re-create two tables every time I need to complete this task.
You need only records with values to be replaced. Have you looked sample DB?
ASKER
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.
ASKER
The references don't have the same values for each ID#
ASKER
This Works...had to remove the [TableName]![EXPRESSION],
Replace(Replace([TableName ]![EXPRESS ION],"@M.P CNT",[Mast erTable]![ PCNT]),"@M .DOLLAR",[ MasterTabl e]![DOLLAR ])
Replace(Replace([TableName
Great! Glad to help!
Then create an update query
Look at sample (tbl11- source, tbl2- replacement rules, qry1- update query)
DB1.accdb