Results 1 to 4 of 4
  1. #1
    lmryckman is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    2

    Comcatenate Help - Too many records being concatenated

    Hi,
    I am trying to concatenate some data and running into an issue...may be somthing silly, but I cannot figure it out.

    Table data:
    1-LTRNumber 3-PartNumber
    LTR 0001 100 S MA11


    LTR 0002 MA 100
    LTR 0002 MA 200

    What I WANT:
    1-LTRNumber 3-PartNumber
    LRT 0001 100 S MA11
    LTR 0002 MA 100, MA 200

    What I am getting:
    1-LTRNumber 3-PartNumber
    LRT 0001 100 S MA11, MA 100, MA 200
    LTR 0002 100 S MA11, MA 100, MA 200

    Query:
    SELECT tblTestRequestParts.[1-LTRNumber], ConcatenatePartNumber([3-PartNumber]) AS PartNumber
    FROM tblTestRequestParts;


    Code:
    Function ConcatenatePartNumber(pstrSQL As String, _
        Optional pstrDelim As String = ", ") _
        As String
        
        Dim rs As ADODB.Recordset
        pstrSQL = "SELECT [3-PartNumber] FROM [tblTestRequestParts] WHERE [3-PartNumber] Is Not Null"
        Set rs = CurrentProject.Connection.Execute(pstrSQL)
        Dim list As String
        list = rs.GetString(, , , pstrDelim)
        rs.Close
        Set rs = Nothing
        ConcatenatePartNumber = Left(list, Len(list) - Len(pstrDelim))
    
    End Function
    Thanks in advance for any help!
    Laura

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    You would need to pass the 1-LTRNumber to the function and use it in the SQL as part of a criteria. As done here:

    http://allenbrowne.com/func-concat.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    lmryckman is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    2
    Quote Originally Posted by pbaldy View Post
    You would need to pass the 1-LTRNumber to the function and use it in the SQL as part of a criteria. As done here:

    http://allenbrowne.com/func-concat.html


    PERFECT!!!
    Thank you so much...I have this working now.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 17
    Last Post: 01-12-2012, 11:25 AM
  2. Formatting a concatenated field
    By kris335 in forum Access
    Replies: 14
    Last Post: 09-21-2011, 09:56 AM
  3. Replies: 2
    Last Post: 08-18-2011, 11:40 AM
  4. Formatting a Concatenated Field
    By CoachBarker in forum Queries
    Replies: 2
    Last Post: 09-23-2010, 09:12 AM
  5. Sum values in concatenated fields
    By jdrubins in forum Reports
    Replies: 4
    Last Post: 09-01-2009, 07:20 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