Results 1 to 4 of 4
  1. #1
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    188

    Concatenate Build String

    I have the below Module from years ago that I'm trying to morph for a new purpose. Below is the query. Attached is the error. I assume this is a syntax issue, but no clue as to what I'm missing. Anyone have any thoughts?

    Code:
    SELECT BuildStr("SELECT Temp_CA_PDF_Filename.PDF_Filename 
    FROM Temp_CA_PDF_Filename","|") AS PDF
    FROM Temp_CA_PDF_Filename;
    Code:
    Function BuildStr(pstrSQL As String, _
            Optional pstrDelim As String = "") _
            As String
    'Created by Duane Hookom, 2003
    'this code may be included in any application/mdb providing
    '   this statement is left intact
    'example
    'tblFamily with FamID as numeric primary key
    'tblFamMem with FamID, FirstName, DOB,...
    'return a comma separated list of FirstNames
    'for a FamID
    ' John, Mary, Susan
    'in a Query
    'SELECT FamID,
    'BuildStr("SELECT FirstName FROM tblFamMem
    ' WHERE FamID =" & [FamID]) as FirstNames
    'FROM tblFamily
    '
    
    
    '======For DAO uncomment next 4 lines=======
    '====== comment out ADO below =======
        'Dim db As DAO.Database
        'Dim rs As DAO.Recordset
        'Set db = CurrentDb
        'Set rs = db.OpenRecordset(pstrSQL)
    
    
    '======For ADO uncomment next two lines=====
    '====== comment out DAO above ======
        Dim rs As New ADODB.Recordset
        rs.Open pstrSQL, CurrentProject.Connection, _
        adOpenKeyset, adLockOptimistic
        Dim strConcat As String 'build return string
        With rs
            If Not .EOF Then
                .MoveFirst
                Do While Not .EOF
                    strConcat = strConcat & _
                    .Fields(0) & pstrDelim
                    .MoveNext
                Loop
            End If
            .Close
        End With
        Set rs = Nothing
    '====== uncomment next line for DAO ========
        'Set db = Nothing
        If Len(strConcat) > 0 Then
            strConcat = Left(strConcat, _
            Len(strConcat) - Len(pstrDelim))
        End If
        BuildStr = strConcat
    End Function
    Thanks!
    Attached Thumbnails Attached Thumbnails S1.jpg  

  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,518
    I normally use DAO, but ADO would require the Microsoft ActiveX Data Objects x.x Library be checked in Tools/References (I have 2.1 in my db).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    188
    That was it!

    Thanks!

  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,518
    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. Dynamically Build Query String
    By Juan4412 in forum Programming
    Replies: 6
    Last Post: 05-24-2017, 10:11 AM
  2. Call a Function to build a string
    By tgall in forum Queries
    Replies: 1
    Last Post: 03-24-2016, 10:12 AM
  3. Replies: 4
    Last Post: 04-15-2013, 04:03 PM
  4. How to Concatenate String Criteria
    By ColPat in forum Programming
    Replies: 2
    Last Post: 06-26-2010, 08:48 PM
  5. concatenate string using loop
    By nengster in forum Programming
    Replies: 0
    Last Post: 02-23-2009, 08:05 PM

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