Results 1 to 9 of 9
  1. #1
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228

    VBA Error When Adjusting Master/Child fields

    On a form I have two listboxes and a subform that is continuous.



    The two listboxes are "Products" and "Code Sets". The idea is that you select a product and a code set and it will show you the codes associated. The list is filtered by a link master/child to the two fields.

    I am trying to make it that when you only have a Product specified, it will show you all codes from all sets. When I go from two linkfields to one, it gives me run-time error '2335'. You must specify the same number of fields when you set the LinkChildFields and LinkMasterFields properties. Can anybody explain why I'm getting this error?

    Just going from

    Code:
    Me.sublist.LinkMasterFields = "Product,Code Set"
    Me.sublist.LinkChildFields = "Product,Code Set"
    to...

    Code:
    Me.sublist.LinkMasterFields = "Product"
    Me.sublist.LinkChildFields = "Product"

  2. #2
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    Update:

    Ignoring the error makes it run perfectly fine, but I still want to know why it throws an error in the first place.

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Where are you running the 2nd one, on the after update of Product listbox? Also maybe try full path Forms![frmMain]![sublist].LinkMasterFields = "Product" instead of "Me."?

  4. #4
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    Yes, the after update.

    The main form is actually using a record source from a table that holds the value of the User, Product and Set. The product listbox control source is field "Product", code set listbox control source "Code Set". I don't think this is the issue. It seems like it wants me to adjust both Master and Child links at the same time.

  5. #5
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    Misread what you were saying, I tried the actual path of "Me." and the same error occurs.

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    I think it is giving error as when you change first LinkMaster, they then are different number of arguments and gives error. Try to set both to "", then change both to "Product"?

    Me.sublist.LinkMasterFields = ""
    Me.sublist.LinkChildFields = ""

    Me.sublist.LinkMasterFields = "Product"
    Me.sublist.LinkChildFields = "Product"

    You might still need to use the full path to subform and not "Me."

  7. #7
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    It is referring to "Me.sublist" which is the name of the subform.

    It indeed works by adjusting to empty values first. That's really odd that it forces you to completely remove the links.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,939
    not sure if it relevant but your initial example

    Me.sublist.LinkMasterFields = "Product,Code Set"

    Code Set as a space, so you need to use square brackets

    Me.sublist.LinkMasterFields = "Product,[Code Set]"

  9. #9
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    not sure if it relevant but your initial example

    Me.sublist.LinkMasterFields = "Product,Code Set"

    Code Set as a space, so you need to use square brackets

    Me.sublist.LinkMasterFields = "Product,[Code Set]"


    It works fine without brackets.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-31-2017, 08:40 AM
  2. Replies: 1
    Last Post: 08-11-2014, 11:25 AM
  3. Replies: 3
    Last Post: 11-24-2013, 06:59 PM
  4. Replies: 5
    Last Post: 03-30-2013, 12:56 PM
  5. Replies: 2
    Last Post: 06-14-2010, 03:25 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