Results 1 to 11 of 11
  1. #1
    dave_282 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2016
    Posts
    8

    Create a field in a table that is the combined results of other fields in the same tbale

    Hi All,



    I want to create a field in a table that is the combined results of other fields in the same table. The table is already set up with all the fields called code1, code2, code3..all the way to 7 and another filed is called Combined Code. I want combined code to show what ever is in each off these 7 fields, which are optional. I want them split with a - .

    Does anyone know where any how I do that?

  2. #2
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Create your CombinedCode field in table design mode first. Then run update query.
    Code:
    UPDATE YourTableName
    SET CombinedCode=code1 & "-" & code2 & "-" & code3 & "-" & code4 & "-" & code5 & "-" & code6 & "-" & code7;
    (Assuming code1, code2, etc are of text type.)

  3. #3
    dave_282 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2016
    Posts
    8
    Thank you. Where do I do that? I thought I'd need to update the field properties in some way? I cant see where to do an update query.

  4. #4
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    As I said:
    1. Create CombinedCode field in table design mode. Meaning right click on table name in navigation bar on the left and choose design mode. Then add new field at the end of fields list with data type Text.
    2. You may use qery wizard to create simple select query of this table of yours. Then in query design mode (again, right click on query name on the left, design mode) change query type to update, then under your CombinedCode field, in "update to" row input:
    code1 & "-" & code2 & "-" & code3 & "-" & code4 & "-" & code5 & "-" & code6 & "-" & code7.
    3. Before you run your query view it first to make sure you'll be updating CombinedCode to proper values.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    The fields code1, code2, code3.....code7 indicate a not normalized structure. This is contrary to basic relational database design. Could you please describe what you are trying to do in plain English -- no Access jargon?

    Before getting too deeply into the nitty gritty of Access, you should do 1 or 2 tutorials on database and table design. It will prevent hours of frustration.

    Here are 2 tutorials from Rogers Access Library that should help. It would take about 30-45 minutes.
    1) Entity Relationship
    2) Normalization

    Good luck.

  6. #6
    dave_282 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2016
    Posts
    8
    Im afraid this didn't work "code1 & "-" & code2 & "-" & code3 & "-" & code4 & "-" & code5 & "-" & code6 & "-" & code7;" . There are columns in a table and I have another column called combinedcode. I want the value of the code1, code 2, code3 etc fields to populate the combinedcode field. I would have though there's some syntax I can just put in default value of the field property or something?

  7. #7
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    I'm afraid default value won't solve your problem. Have you tried update query? Or are you still waiting for some magic syntax? Also you really should read links provided by orange.

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    If you are trying to create field that will be automatically populated when the other fields are populated, you can't. Excel is good for that sort of thing, but not Access. The only way would be to use a form with a bit of VBA to populate that field.

    That said, it is bad database practice to include calculated fields in a database table. Create a normal select query containing the calculation instead.

  9. #9
    dave_282 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2016
    Posts
    8
    Having an update query isn't ideal as I need it to do it automatically, not have something else that needs to be run. Yeah I knew everything in those links.

  10. #10
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Then do it in BeforeUpdate event or something, as John_G suggests.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    1. As Orange suggested, your data structure is not normalized. If you understand this and still want this structure, then all good.

    2. Saving calculated data is usually a bad idea. It is certainly not necessary in this case. Calculate the 'combined code' when needed.

    3. If a field is empty, the "-" will still concatenate by using the & operator. If the field has Null and you want to suppress the "-", try:

    code1 & "-" + code2 & "-" + code3 & "-" + code4 & "-" + code5 & "-" + code6 & "-" + code7
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 01-08-2016, 07:09 PM
  2. Replies: 3
    Last Post: 08-18-2014, 10:30 AM
  3. Replies: 3
    Last Post: 08-05-2011, 08:13 PM
  4. Replies: 1
    Last Post: 07-10-2011, 01:28 PM
  5. Using tbale field in Lookup Wizard
    By dotancohen in forum Database Design
    Replies: 5
    Last Post: 12-10-2009, 02:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums