Results 1 to 8 of 8
  1. #1
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83

    Item not found

    Ok, banged my head on this one enough. Found this function to condense several rows into one, concatenating a field, separating entries by commas.

    I am getting an error message #3265 Item not found in this collection on the line I've highlighted in Red. I can't figure out what I could be doing wrong and was hoping I could get some direction.

    I have this in Query1 (built from "qConstraints") with the following fields:
    RB_STY_ID
    Field1: Conc("MAN_CON_DESC","RB_STY_ID",[RB_STY_ID],"qConstraints")

    Public Function Conc(Fieldx, Identity, Value, Source) As Variant
    Dim cnn As DAO.Connection
    Dim rs As DAO.Recordset

    Dim SQL As String
    Dim vFld As Variant


    vFld = Null

    SQL = "SELECT [" & Fieldx & "] As Fld" & _
    " FROM [" & Source & "]" & _
    " WHERE [" & Identity & "]=" & Value

    ' open recordset.
    Set rs = CurrentDb.OpenRecordset("qConstraints", dbOpenDynaset)

    ' concatenate the field.
    Do While Not rs.EOF
    If Not IsNull(rs!Fld) Then



    vFld = vFld & ", " & rs!Fld
    End If
    rs.MoveNext
    Loop
    ' remove leading comma and space.
    vFld = Mid(vFld, 3)

    Set cnn = Nothing
    Set rs = Nothing

    ' return concatenated string.
    Conc = vFld
    End Function

    Thanks!

  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
    Is Fld a field in qConstraints? I see it in the SQL string you've built, but you haven't done anything with that. Did you mean to open the recordset on the SQL string rather than qConstraints?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    try running that SQL string first?

  4. #4
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    I did try to run the SQL but nothing came up. In debugging mode, if I hover over the 3 fields, "Fieldx", "Source", and "Identity" it shows my data.

    Thanks

  5. #5
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    Fld is the alias for Fieldx, which is field MAN_CON_DESC in qConstraints

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Try this:

    Set rs = CurrentDb.OpenRecordset(SQL, dbOpenDynaset)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    Got it! Thanks for all of your help! Works perfectly. Learning differences between DAO and ADO.

    Public Function Conc(Fieldx, Identity, Value, Source) As Variant
    Dim cnn As DAO.Connection
    Dim rs As DAO.Recordset
    Dim SQL As String
    Dim vFld As Variant


    vFld = Null

    SQL = "SELECT [" & Fieldx & "] as Fld" & _
    " FROM [" & Source & "]" & _
    " WHERE [" & Identity & "]=" & Value

    ' open recordset.
    Set rs = CurrentDb.OpenRecordset(SQL, dbOpenDynaset)

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problem, 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. Return most recent entry for each item
    By GenAp in forum Queries
    Replies: 1
    Last Post: 02-04-2010, 05:30 AM
  2. Module not found
    By nooby in forum Modules
    Replies: 1
    Last Post: 12-02-2009, 02:20 PM
  3. Can't alays select an item from a list box
    By bomber in forum Access
    Replies: 0
    Last Post: 10-16-2009, 10:01 AM
  4. Replies: 0
    Last Post: 08-26-2009, 11:51 AM
  5. Combo-box to select item to edit in Form
    By DHavokD in forum Forms
    Replies: 7
    Last Post: 06-05-2009, 01:39 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