7 Replies Latest reply on Dec 3, 2010 10:39 AM by philmodjunk

# Using field names in a calculation

### Title

Using field names in a calculation

### Post

I have a table with several fields including, for arguments sake, FieldA and FieldB.

I need FieldA to be a calculated field whereby it's value equals the value in another field in the record whose name matches the value in FieldB

• ###### 1. Re: Using field names in a calculation

Is this what you mean?

Field B = "Field 1"

Field 1 = 5
Field 2 = 6

Field A thus = 5

If so, then GetField ( Field B ) will do this for you.

• ###### 2. Re: Using field names in a calculation

Phil you are a genius...this is exactly the scenario!

But now I need it to be slightly more complicated! Instead of Field B = "Field 1" it only equals Field 1 minus the last five characters in the name of field 1.

So for ex

Field B = "XXX"

XXX12345 = 5

YYYY12345 = 6

Thus I want Field A = 5 when Field B = "XXX", but Field A = 6 when Field B = "YYYY"

Hope this makes sense! Sorry for the convolutedness!

Cheers, Chris

• ###### 3. Re: Using field names in a calculation

You can use an If or case function.

Or you can use:

GetField ( Field B & "12345" )

• ###### 4. Re: Using field names in a calculation

Hi Phil - hopefully this is the last time I'll bug you!

I'll use your suggestion GetField ( Field B & "12345" ). The "12345" is not literally the same everytime...how do I put generic spacers in there that signify letters or numbers (ie random characters)

Cheers

Chris

• ###### 5. Re: Using field names in a calculation

I don't see how that could evaluate correctly to a specific field name. Your expression must evaluate to a name that exactly matches the name of a field.

• ###### 6. Re: Using field names in a calculation

Phil you are right. I tried using GetField ( FieldB & * ) or GetField ( FieldB & "*" ) and it didnt work so I'll stick with GetField ( Field B & "12345" ).

Thanks so much. I don't know who pays you but they should pay you more.

• ###### 7. Re: Using field names in a calculation

Actually, I'm seeking better employment than my current job...