Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    18

    Unanswered: Change the number of LinkFields

    Hi
    I have a subform linked to its parent by 3 fields.

    I'd like to have a dynamic link form-subform, so that when any of these fields is empty in the master form, the link doesn't take care of that field.

    My idea is that:

    If IsNull(Me!FieldA) Then
    If IsNull(Me!FieldB) Then
    Me![SubF].LinkChildFields = "FieldC"
    Me![SubF].LinkMasterFields = "FieldC"
    Else
    Me![SubF].LinkChildFields = "FieldC;FieldB"
    Me![SubF].LinkMasterFields = "FieldC;FieldB"
    End If
    Else
    If IsNull(Me!FieldB) Then
    Me![SubF].LinkChildFields = "FieldC;FieldA"
    Me![SubF].LinkMasterFields = "FieldC;FieldA"
    Else
    Me![SubF].LinkChildFields = "FieldC;FieldB;FieldA"
    Me![SubF].LinkMasterFields = "FieldC;FieldB;FieldA"
    End If
    End If

    But.. an error arises blocking the code at any LinkChildFields level, stating that I "need to use the same number of fields when setting up" these properties.

    Which could be the proper workaroud?

    - Edited: corrected an error in the code..
    Last edited by leraffat; 09-22-08 at 08:57.

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Good grief!

    Why would you need to do this?? Kinda smells like a table design error to me

    Try starting with no defined Link Fields? Dunno, never tried such a thing ^^
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Sep 2003
    Posts
    18
    Quote Originally Posted by StarTrekker
    Good grief!

    Why would you need to do this?? Kinda smells like a table design error to me

    Try starting with no defined Link Fields? Dunno, never tried such a thing ^^
    eh eh eh!
    Form and subform tables have a direct relationship on FieldC, I'm trying this solution only to filter runtime the subform records..

    FieldA and FieldB are unbound on the parent form

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Mnnn... so shouldn't you be using the Filter property or the RecordSource then?

    I wouldn't have thought that the link fields couldn't refer to unbound controls... but again, I've never tried
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I would establish the link (Other than in the relationships tables) between the subform and mainform by putting this in for the subform recordsource:
    Select * from mySubTable where IDField = " & Forms!MyMainFormName!IDField & ""
    and then add the IDField on the subform (can be invisible), and for a default value put in this:
    =Forms!MyMainFormName!IDField

    Then you don't really need to worry about setting the .LinkChildFields or .LinkMasterFields coding.
    Last edited by pkstormy; 09-22-08 at 22:28.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •