Results 1 to 9 of 9
  1. #1
    FrustratedAlso is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    35

    Question Photos.FileNames Attachments

    When you query Photo.name, you get a line for each photo name attached to a record



    1 aunt sally a.jpg
    1 aunt sally b.jpg
    1 aunt sally c.jpg
    2 Uncle Joe x.jpg
    3 Cousin Bob l.jpg

    What I would like is to have it appear like this

    1 aunt sally a.jpg; b.jpg; c.jpg
    2 Uncle Joe x.jpg
    3 Cousin Bob L.jpg

    Suggestions or Solutions ?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    That is an attachment field type?

    Not sure if can be applied but review http://allenbrowne.com/func-concat.html
    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.

  3. #3
    FrustratedAlso is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    35
    Yes it is an attachment field type. The stumbling block might be the record type? I tested and the function is passing the right key to look up.

    Here is what I came up with:
    Code:
    Public Function ConcatRelated(rNbr As String) As Variant
       On Error GoTo Err_Handler
       'Purpose: Generate a concatenated string of related records.
       'Return: String variant, or Null if no matches.
       'Arguments: strField = name of field to get results from and concatenate.
       ' strTable = name of a table or query.
       ' strWhere = WHERE clause to choose the right values.
       ' strOrderBy = ORDER BY clause, for sorting the values.
       ' strSeparator = characters to use between the concatenated values.
       'Notes: 1. Use square brackets around field/table names with spaces or odd characters.
       ' 2. strField can be a Multi-valued field (A2007 and later), but strOrderBy cannot.
       ' 3. Nulls are omitted, zero-length strings (ZLSs) are returned as ZLSs.
       ' 4. Returning more than 255 characters to a recordset triggers this Access bug:
       ' http://allenbrowne.com/bug-16.html
       Dim rs As DAO.Recordset 'Related records
       Dim rsMV As DAO.Recordset 'Multi-valued field recordset
       Dim strSql As String 'SQL statement
       Dim strOut As String 'Output string to concatenate to.
       Dim lngLen As Long 'Length of string.
       Dim bIsMultiValue As Boolean 'Flag if strField is a multi-valued field.
       strSeparator = "; "
       'Initialize to Null
       ConcatRelated = Null
    
       'Build SQL string, and get the records.
       strSql = "SELECT Inventory.[Photos].[FileName] From Inventory where Inventory.[Number] = " & rNbr
       Set rs = DBEngine(0)(0).OpenRecordset(strSql, dbOpenDynaset)
       'Determine if the requested field is multi-valued (Type is above 100.)
       bIsMultiValue = (rs(0).Type > 100)
        'Loop through the matching records
        Do While Not rs.EOF
            If bIsMultiValue Then
                'For multi-valued field, loop through the values
                Set rsMV = rs(0).Value
                Do While Not rsMV.EOF
                   If Not IsNull(rsMV(0)) Then
                      strOut = strOut & rsMV(0) & strSeparator
                   End If
                   rsMV.MoveNext
                Loop
                Set rsMV = Nothing
            ElseIf Not IsNull(rs(0)) Then
               strOut = strOut & rs(0) & strSeparator
            End If
            rs.MoveNext
        Loop
        rs.Close
        'Return the string without the trailing separator.
        lngLen = Len(strOut) - Len(strSeparator)
        If lngLen > 0 Then
           ConcatRelated = Left(strOut, lngLen)
        Else
           ConcatRelated = rNbr ' put this in to see what I get
        End If
    Exit_Handler:
        'Clean up
        Set rsMV = Nothing
        Set rs = Nothing
        Exit Function
    Err_Handler:
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "ConcatRelated()"
        Resume Exit_Handler
    End Function

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Use code tags when copy/paste code (I edited your post). If you use indentation in code it will be retained and makes it more readable.

    What else happens? Does the data concatenate?
    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.

  5. #5
    FrustratedAlso is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    35
    No, I returns nulls, I don't think is goes through the records. Maybe the record type isn't ".> 100?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    I got this to work. Didn't matter if I pulled data from the table or query like you describe in first post. That it works with recordset based on table instead of query does surprise me.

    Maybe doesn't matter but you declare rNbr as a string. Is it really a number?

    Show the expression calling the function. Are you calling from a query or textbox?
    Last edited by June7; 04-04-2012 at 10:16 AM.
    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.

  7. #7
    FrustratedAlso is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    35
    It is a string in the format of nnnnn-nn. Calling from a query on the Inventory table which also is the table containing the jpg's Expr1: ConcatRelated([Number])
    Attachment 7037

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    I am surprised no error message.

    Value for text datatype field needs apostrophe delimiters:

    ... Inventory.[Number] = '" & rNbr & "'"

    Date values use # delimiter.

    The function call is correct.
    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.

  9. #9
    FrustratedAlso is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    35
    AWESOME!!!! Thanks sooooo Much

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

Similar Threads

  1. photos
    By nashr1928 in forum Forms
    Replies: 4
    Last Post: 11-19-2010, 11:56 PM
  2. Tabs and Photos
    By Nixx1401 in forum Forms
    Replies: 1
    Last Post: 07-19-2010, 02:42 PM
  3. What is the best way to handle photos?
    By TundraMonkey in forum Database Design
    Replies: 2
    Last Post: 08-12-2009, 10:52 PM
  4. Exporting Quieres - Filenames
    By jquickuk in forum Programming
    Replies: 1
    Last Post: 05-02-2009, 06:51 PM
  5. Adding filenames to pictures
    By Plumber in forum Forms
    Replies: 1
    Last Post: 02-11-2009, 10:34 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