Results 1 to 12 of 12
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Using ConcatRelated In VBA

    Greetings - I am attempting to use the ConcatRelated Function by Allen Browne in a recordset. My syntax is not throwing any errors - however nothing is being input either. Am I double quoting incorrectly? What should I do in order for this to execute succesfully?

    Code:
    rsInsert![ProfencyScore] = ConcatRelated("" & userIDField & "", "SchoolData", "" & luid & " = " & rsSelect(luid).Value)


  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,652
    Try

    ConcatRelated(userIDField, "SchoolData", "luid = " & rsSelect(luid).Value)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Or if the field argument is the actual field name (I was thinking it was a variable):

    ConcatRelated("userIDField", "SchoolData", "luid = " & rsSelect(luid).Value)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by pbaldy View Post
    Or if the field argument is the actual field name (I was thinking it was a variable):

    ConcatRelated("userIDField", "SchoolData", "luid = " & rsSelect(luid).Value)
    In my VBA this gives me an error of Compile Error: Expected: list sperator or )

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Hard to tell without the rest of the code. Is luid a variable or a field name? If the latter:

    ConcatRelated("userIDField", "SchoolData", "luid = " & rsSelect!luid)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    You are referencing a recordset rsSelect for an input parameter? Try:

    rsSelect("luid")

    or

    rsSelect!luid

    And you are updating a field in recordset rsInsert? Why would you save this calculated result to table?

    Post your complete procedure if you need more help.
    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
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by pbaldy View Post
    Hard to tell without the rest of the code. Is luid a variable or a field name? If the latter:

    ConcatRelated("userIDField", "SchoolData", "luid = " & rsSelect!luid)
    Let me try to elaborate

    userIDField is a field in my table
    SchoolData is the table name
    luid is a field in my table
    rsSelect!luid is a variable

  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,652
    I'll get out of the way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by June7 View Post
    You are referencing a recordset rsSelect for an input parameter? Try:

    rsSelect("luid")

    or

    rsSelect!luid

    And you are updating a field in recordset rsInsert? Why would you save this calculated result to table?

    Post your complete procedure if you need more help.
    That removes the error, but no data is insert into the table

    Full on syntax
    Code:
    
    DoCmd.RunSQL ("Create Table [_Vendor1] (loggedinuserid text,  profencyScoretext);")
    Dim rsSelect As DAO.Recordset
    Dim rsInsert As DAO.Recordset
    Dim db As DAO.Database
    Set db = CurrentDb
    Set rsSelect = db.OpenRecordset("Select DISTINCT " & luid & " FROM [SchoolData]")
    Set rsInsert = db.OpenRecordset("_Vendor1")
    Do While Not rsSelect.EOF
    	rsInsert.AddNew
    	rsInsert!loggedinuserid = rsSelect(luid).Value
    	rsInsert![ProfencyScore] = ConcatRelated("" & userIDField & "", "SchoolData", "" & luid & " = " & rsSelect(luid).Value)
    	rsInsert.Update
    	rsSelect.MoveNext
    Loop

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Still wonder why saving to table.

    Code shows incorrect syntax - not corrected as already suggested.

    rsInsert!loggedinuserid = rsSelect!luid
    rsInsert!ProfencyScore = ConcatRelated("userIDField", "SchoolData", "luid = " & rsSelect!luid)

    Is fieldname really spelled [ProfencyScore] and not [ProficiencyScore]?

    Or instead of using recordset objects, consider:

    CurrentDb.Execute "INSERT INTO [_Vendor1](loggedinuserid, ProfencyScore) SELECT DISTINCT luid, ConcatRelated('userIDField', 'SchoolData', 'luid = ' & [luid]) AS PScores FROM SchoolData"

    Tested, it works.
    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.

  11. #11
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    @June07 - I was attempting to go the recordset route as the ConcatRelated() function truncates at 255 characters and I have run into a few instances where the text excceeds that limit. So I was trying to come up with an alternative to continue using the same function, but change syntax to handle larger characters.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    According to Allen, the truncation occurs if you use the function in a query and then use that query in another query. So I can see how the SQL statement I suggested might fail.

    Maybe committing the data to a memo field in table is the best approach or maybe you should use the function in a later stage of a process. Depends on what you are really trying to accomplish. The function could be called from a textbox on a report.

    For more than 255 characters the field must be memo type. Your code is creating table with only text type. So your recordset approach and saving to table does nothing to resolve the issue of more than 255 characters.

    Following code works:
    Code:
    DoCmd.RunSQL ("Create Table [_Vendor1] (loggedinuserid text,  profencyScore memo);")
    Dim rsSelect As DAO.Recordset
    Dim rsInsert As DAO.Recordset
    Dim db As DAO.Database
    Set db = CurrentDb
    Set rsSelect = db.OpenRecordset("Select DISTINCT luid FROM [SchoolData]")
    Set rsInsert = db.OpenRecordset("_Vendor1")
    Do While Not rsSelect.EOF
        rsInsert.AddNew
        rsInsert!loggedinuserid = rsSelect!luid
        rsInsert![ProfencyScore] = ConcatRelated("userIDField", "SchoolData", "luid = " & rsSelect!luid)
        rsInsert.Update
        rsSelect.MoveNext
    Loop
    However, I recommend not using CREATE TABLE. Create the table manually and make it permanent then instead delete records at beginning of the Sub:

    CurrentDb.Execute "DELETE FROM [_Vendor1]"
    Last edited by June7; 11-01-2017 at 10:19 PM.
    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.

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

Similar Threads

  1. Apply conditions to ConcatRelated()
    By Forbes in forum Access
    Replies: 0
    Last Post: 03-13-2017, 03:36 PM
  2. ConcatRelated
    By bbilotta in forum Programming
    Replies: 28
    Last Post: 03-07-2017, 10:28 PM
  3. concatrelated problem
    By spacerobot in forum Programming
    Replies: 12
    Last Post: 04-05-2016, 08:08 AM
  4. ConcatRelated Help
    By aog928 in forum Programming
    Replies: 4
    Last Post: 09-27-2014, 10:39 AM
  5. When concatrelated() just isn't enough.
    By ork2002 in forum Programming
    Replies: 2
    Last Post: 03-11-2014, 01:32 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