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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a combined field in a table 1

Status
Not open for further replies.

dorisq

Technical User
Feb 9, 2005
4
US
Hi,
My problem is this:
I need to create a field in an access table that is a combination of values from three other fields in the same record. I can't figure out how to do this. Can anyone help?
Thanks so much!
dorisq
 
Why would you need to do that?

It violates rules of normalization, will create headaches when one of the fields it is derived from alters value...

Why not just concatenate/calculate on the fly whenever you need to display it?

Roy-Vidar
 
WOW, Thank you for answering me so quickly.
How would I make the field calculated so it would create itself whenever I needed it to?
 
When querying the database with a SQL select instruction you may do lot of calculations...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
For instance in a form, you could use a controlsource for a control with a formula like this:

[tt]=txtCtrl1 & " " & txtCtrl2 & " " & txtCtrl3[/tt]

This should concatenate the contents of three controls named txtCtrl1... into one string with a space between. This should also work in a report.

Another way, is to use some relevant event of the form to perform the concatenation (here without space), for instance the forms on current event, the after update event of some of the involved controls, in the event procedure (hit the button with three dot's on the right of the event property to enter VBE) enter something like this.

[tt]Me!txtResult = Me!txtCtrl1 & Me!txtCtrl2 & Me!txtCtrl3[/tt]

Replace txtCtrl1... with the names of your controls...

I see you're a new member, welcome to Tek-Tips.

Here's one of the faqs on how to get the most out of the membership faq181-2886

Good Luck!

Roy-Vidar
 
Hi Roy,
Thanks so much for your help. I hate to be a bother, but when I spoke to my computer guy (he's just as confused as I am :) He said that this is what I need to ask you:
We need a key field in a table that is made up of three values from existing fields in the table. How would I get that key field to fill automatically after I've finished with the data entry? Would I create a macro to add the three existing field together? Thank you again for being so patient with all my questions.
dorisq
 
No you don't need that, it's still violating normal forms - if you need a primary key consisting of three fields, you make those three fields a compound/composite primary key, not create another field to stuff the concatentation of them.

In table design view, select all three fields (mouse + ctrl key), then click the primary key button on the toolbar...

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top