Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refer to field using concatenated text 4

Status
Not open for further replies.

simon1974

Technical User
Apr 2, 2002
43
US
I am concatenating several pieces of data together which will tell me which field (among several) from which to pull data. The question is, how do I refer in a formula to a field by using concatenated text. Can't figure it out, would appreciate any help.

 
Fields(enter text here)

Ex. if field name is [A]&"1" then

Fields([A]&"!")
 
Where are you wanting to put the formula? In a query, VB?...
 
Shannon,

I need to stick it in a query. Thanks for any help you might offer.
 
It appears that the "fields" function does not work in a query. Can anyone offer any further help? Thanks
 
If you merely want to concatenate fields in a query design window, ensure the tables that contain the fields are displayed, then in the Field line of any column, the format is something like:

[tablename].[fieldname] & [tablename].[fieldname] & "normal text can also be inserted like this" & [tablename].[fieldname]

If there are no duulpicate names from any of the tables, you can omit the [tablename]. portions from above...... Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Thanks Robert. What I really need to do is this -- I have several fields that have a preset payment amount (named, for example, [Payment1], [Payment2], [Payment3]. I have another field that does a calculation to determine which period I am in and returns a 1,2, or 3. I want a final field to display the current payment, which is determined by the 1,2, or 3. So what I was hoping to do is use concatenation somehow to link "Payment" with the calculated 1,2, or 3 for the field reference so that I can get it to dynamically refer to either Payment1, Payment2, or Payment3 based on which period I am in. I looked at IIF, but I don't think that I can include multiple else statements, and there are 25 periods. Thanks again, let me know if there is anything I can do.
 
Have you looked at the select case function???? Although you can't put this into the query directly, you can create a module that can return the correct values you require and then caoncatenate them into your query....

I am kind of confused with your situation....you start by saying you have three periods, but finish by saying you have 25......

Can you send me the db with a brief description of what query is involved and your expected results.....Be happy to take a look-see and help you out.....if you can send it, I use Access97 and please zip to under 1MB or the exchange server will strip off the atatchment Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Simon,

Sooner or later someone will get sick of me saying this, but it looks a lot like you should do some work on your table scheme. There's a great article on my website (not written by me) that explains data normalization. If you follow the principles in that article you'll get around this problem quite easily.

Jeremy

PS: The article is in the developer's section, which is a little mucked up right now. At the home page, right click on the Developer's Section link and bring it up in a new window. You'll be able to get the article from there. =============
Jeremy Wallace
Designing, Developing, and Deploying Access databases since 1995.
 
You have the solution...I think a nested iif statement will work:

Current Payment: Iif([period]=1,[Payment1],iif([period]=2,[Payment2],[Payment 3]))

If period is a calculated value within your query then just replace ([period]) with your calculation. One other thing to note is that the above statement assumes ONLY values 1, 2 or 3 will be inherited by [period].
[yinyang]

ps. let me know how you get on
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top