Results 1 to 15 of 15
  1. #1
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143

    Can't reference a Multi-Value field in an update query. How can I get around needing a MVF?

    I have one table with a single multivalue field that I just created today and it's already causing problems. The table is a list of product lots:


    (simplified version of the table)
    LotNumber OGPesticides OldLotNum
    2011-5482-6624-0071 1, 2
    2011-5482-6638-2086 3

    Every pesticide used has to end up on a report used for irl labeling, so it's important that the list is complete. Previously we've only used one so it was a single value field, but we have recently needed to add more and a multi-value field seemed to be just what I needed.

    I have come across problems when trying to use an update query. We often divide a product lot into the old lot and a new one with all the same details. I have a query that (when I only had single value fields) would allow a user to input the new lot number in [LotNumber] and the originial lot number in [OldLotNum] and the query would set all the detail fields in the new lot to be equal to the detail fields from the old lot. Now I get error 3844 every time saying that I can't reference a MVF in an update query.

    I am hoping one of you guys can either help me get the update query to work, or help me find a way around using the multi-value field without losing any data.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    No idea if it will work but you need to reference the value property of the field. The problem is the MV field is like a many to many relationships table, but because it is hidden away you cannot access it as you would with the normal way of doing things. Not sure if this will do what you want, but about the only thing I could find online which looks like a solution

    https://stackoverflow.com/questions/...ield-in-access

    Personally I would drop the MV field in favour of a many to many linking table

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I am with Ajax on this sugject.
    I have never and will never use a MVF. I would suggest creating a properly normalized structure. It will save you from major headaches and save you loads of time.

    Having said that, I understand some people will use MVFs. I did find these sites that might help:
    http://www.utteraccess.com/forum/Mul...-t1984616.html
    https://stackoverflow.com/questions/...s-in-ms-access
    https://social.msdn.microsoft.com/Fo...orum=accessdev
    http://www.utteraccess.com/forum/lof.../t1944468.html

  4. #4
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    I'm hesitant to use a many to many linking table since the way that our label reports are designed doesn't leave room for a details section to have multiple details. Everything needs to be on one line since our whole set up is for 2.25" x 1.25" labels and there is a lot of info that goes in that tiny space. The MVF was able to work at first because it had both values in a single detail section with just a comma separating them. If there is a way to do that with a many to many, that would be great!
    I haven't gotten around to trying INSERT INTO query, but will try to make time this weekend. I'm thinking that I'll end up needing both an update query for the other detail fields and then an insert into query as well.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    See
    Concatenate values from related records
    http://www.allenbrowne.com/func-concat.html

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    If you really must use MVF, review https://support.office.com/en-us/art...ad=US&fromAR=1
    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
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    As other have said, the MVF is a "mechanism" within MS Access. It was intended to "simplify things" for users. Developers/database designers would use normalized tables and relationships. Many/most people avoid them because they are limited/specific to MS Access and deal with hidden entities.
    As a poster in another forum said:
    The values contained in a multi-value field are actually contained as separate records in a hidden table, they are just presented as a single comma-delimited string for convenience....They can be very useful in certain very specific circumstances; but by-and-large I've found them to be more trouble than they are worth.

  8. #8
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    Quote Originally Posted by ssanfu View Post
    See
    Concatenate values from related records
    http://www.allenbrowne.com/func-concat.html
    Ssnafu, I tried using the ConcatRelated function as that seemed like the best option where I could get around using a MVF. I used the function in a text box on the label report:
    "Approved Pesticides: " & ConcatRelated("PesticideName","tblLotPesticides"," LotID = " & [tblLot.LotID])
    [tblLot.LotID] is the name of the query field.
    But when I try to use it, I get asked for a ConcatRelated parameter value, and the text box returns #Type!
    Was there something that I missed?

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    As I said, I have never use a MVF, have never used Allen Browne's Concat function so I can only make a guess.

    "Approved Pesticides: " & ConcatRelated("PesticideName","tblLotPesticides"," LotID = " & [tblLot.LotID])
    [tblLot.LotID] is the name of the query field.
    First, you shouldn't have the quote at the beginning of the name nor the ampersand.
    In the query design view, it would/should look like
    Code:
    Approved Pesticides: ConcatRelated("PesticideName","tblLotPesticides","  LotID = " & LotID)
    Do you have two fields named "LotID" in the query? If you DO have two fields in the query named "LotID", try

    Code:
    Approved Pesticides: ConcatRelated("PesticideName","tblLotPesticides","  LotID = " & tblLot.LotID)
    'NO brackets

  10. #10
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    I was not using ConcatRelated in the query, but instead in a textbox on the report that is based on a query. So the textbox is: ="Approved Pesticides: " & ConcatRelated("PesticideName","tblLotPesticides"," LotID = " & [tblLot.LotID])

    The query calls on multiple tables two of which have a field LotID, but only one is used in the query. If I attribute a report textbox to that field, the option available is tblLot.LotID
    I hope that cleared up what has been happening so far.

    I then tried changing the [tblLot.LotID] to tblLot.LotID, which the textbox automatically changed to [tblLot].[LotID] but it kept thinking that [tblLot] was a field and would ask for a parameter value for both ConcatRelated and tblLot.

    So I next tried making a concat field in the source query: AppPests: ConcatRelated("PesticideName","tblLotPesticides"," LotID = " & [tblLot].[LotID]) When I try to run the query I get a message box that says "Undefined function 'ConcatRelated' in expression." I double checked that I didn't miss any part of Allen Browne's function and I didn't. So I'm at a loss again.

    But am I correct in thinking that the ConcatRelated function is not meant to be used with MVF's, but to make one to many relationships appear as MVF's? I think I forgot to mention that I created a junction table (tblLotPesticides) that is designed with fields LotPestID, LotID and PesticideID. These are related to tblLot.LotID and tblPesticides.PesticideID

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Did you put the function in a general code module?

    Don't prefix field with table name unless there is more than one field in the query named LotID.

    The function does handle MVF.
    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.

  12. #12
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    Yes, it's in a general code module.

    I tried changing the tblLot.LotID to just LotID on the report textbox, but the result was still the same, it still asks for a ConcatRelated parameter value and then returns #Type!.

    I tried again using the function in the source query itself but referencing tblLot and then tblPesticides instead

    AppPest: ConcatRelated("PesticideID","tblLot","LotID = " & [tblLot].[LotID])
    And
    AppPest: ConcatRelated("PesticideID","tblPesticides","Pesti cideID = " & [PesticideID.value])
    and I still get "Undefined function 'ConcatRelated' in expression." with each variation.

    Being pretty new to VBA, I feel like there could be something I messed up somewhere, but I wouldn't know how to let you know where I messed up..
    Thank you everyone for your patience.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    All I can say is declaring the function as Public in a general module works for me. I can call the function from query or textbox. Make sure the module does not have same name as the function.

    LotID is a number type?

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  14. #14
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    Ah hah! I did call the module ConcatRelated! Once I changed the name everything worked perfectly!

  15. #15
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    Thank you everyone for your help!
    It's often the little things that get me.

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

Similar Threads

  1. Query to update a field from a reference table
    By PCartland in forum Queries
    Replies: 8
    Last Post: 02-03-2017, 02:29 PM
  2. Replies: 1
    Last Post: 05-21-2015, 07:04 AM
  3. Update Query with a Multi-Value Field
    By tanyalee123 in forum Queries
    Replies: 6
    Last Post: 04-07-2014, 11:57 AM
  4. How to update Multi Value Field via VBA
    By gopherking in forum Programming
    Replies: 6
    Last Post: 07-14-2013, 03:05 AM
  5. still needing help on update query button
    By cdell7up in forum Access
    Replies: 3
    Last Post: 08-04-2012, 11:21 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