Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2009
    Posts
    9

    Red face Unanswered: concatenate coupe of fields in one new field

    Hi all,


    In troulble again,

    I have to concatenate couple of values in a single field.
    The values are picked from a form
    Value1- datetime - form.combo1
    value2-text- - form.combo2
    value3- text - form.combo3

    te result should be as:
    new column value: "value.combo1" + "-" + "value.combo2" + "value.combo3"

    No idea how that could be done .Shall I have a function for it or would it be done trough query .

    Any help would be appreciated

    Thanks
    Milena

  2. #2
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    Replace the + character with & and : with = to give you
    new column value= "value.combo1" & "-" + "value.combo2" & "value.combo3"
    This assumes that the new column value is the name of the field. More importantly new column value must be one word as you are using reserved words.

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You've also got the cart before the horse!

    value.combo1

    should be

    combo1.Value

    or, since Value is the default property for comboboxes, simply

    combo1

    will do just fine. So in VBA code

    NewColumnValue = combo1 & "-" & combo2 & combo3

    or in a calculated field in a query

    NewColumnValue: combo1 & "-" & combo2 & combo3
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    mynewcolumn = combo1.value & combo2.value & combo3.value

    or
    mycolumnseperator = "|"
    mynewcolumn = combo1.value & mycolumnseperator & combo2.value & mycolumnseperator & combo3.value

    or
    mynewcolumn = format(combo1.value,"0000000") & format(combo2.value,"0000000") & format(combo3.value,"0000000")

    but htis does beg the question why you are creating a composite vlaue
    it would make more sense to me to create 3 columns in the db that represent the values of the combo box.
    why
    well its more logical
    its easier to decompress/represent when you display the row next tims around.... you don't have to unpack the composite field to set the combo boxes.
    making a composite vlaue has the whiff of dodgy design
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jan 2009
    Posts
    9
    Thank you guys for help . I got it working ok. Now the problem is that the expresssion returns the month date part as 2009229 for example .I want it to be 20090229. How ca I do that .Here is my current expresssion:

    DatePart("yyyy",[cboReportingPeriod]) & "" & DatePart("m",[cboReportingPeriod]) & "" & DatePart("d",[cboReportingPeriod])

    What do I need to add or change here so I get as result YYYYMMDD and not YYYYMDD for the months up to October(where it will show as 10 anyway)

    Thanks in advance

  6. #6
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    Use the FORMAT statement

    DatePart("yyyy",[cboReportingPeriod]) & "" & FORMAT(DatePart("m",[cboReportingPeriod]),"00") & "" & FORMAT(DatePart("d",[cboReportingPeriod]) ,"00")

    This will force the Month and Day to be two digits e.g. 01 02 etc

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by Poppa Smurf
    Use the FORMAT statement

    DatePart("yyyy",[cboReportingPeriod]) & "" & FORMAT(DatePart("m",[cboReportingPeriod]),"00") & "" & FORMAT(DatePart("d",[cboReportingPeriod]) ,"00")

    This will force the Month and Day to be two digits e.g. 01 02 etc
    ..or even format(mydatevalue, "yyyymmdd")
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    lol Poppa Smurf,... way to make it complex!! ^^
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  9. #9
    Join Date
    Jan 2009
    Posts
    9
    Thank you very much all!
    Of course it worked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •