Results 1 to 11 of 11
  1. #1
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155

    Linking through code

    Can we change linking with the subform through code? How?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Don't know what that means. Linking to what?
    You mean changes its record source? Change its parent/child linked fields? Change the subform control source object? In any of those cases, yes.
    If something else, then I don't know.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by Micron View Post
    Don't know what that means. Linking to what?
    You mean changes its record source? Change its parent/child linked fields? Change the subform control source object? In any of those cases, yes.
    If something else, then I don't know.

    Change its parent/child linked fields

  4. #4
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Yes . From the main form

    Code:
    Me.YourSubFormContainer.LinkMasterFields="BlahBlah"
    Me.YourSubFormContainer.LinkChildFields="Filbble"
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by Minty View Post
    Yes . From the main form

    Code:
    Me.YourSubFormContainer.LinkMasterFields="BlahBlah"
    Me.YourSubFormContainer.LinkChildFields="Filbble"



    The following code :


    Me.CASH_OFFICE_subform.LinkMasterFields = FNAME
    Me.CASH_OFFICE_subform.LinkChildFields = FNAME

    asks for the variable FNAME.
    Both Master and Child fields have the same name (FNAME).

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    you left off the quotes per example
    FNAME isn't a variable - or at least if it is, it won't work. FNAME is a field name but without quotes it's probably being interpreted as an object when it expects a string value.
    Either enclose in quotes or maybe brackets: "FNAME" or [FNAME]

  7. #7
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by Micron View Post
    you left off the quotes per example
    FNAME isn't a variable - or at least if it is, it won't work. FNAME is a field name but without quotes it's probably being interpreted as an object when it expects a string value.
    Either enclose in quotes or maybe brackets: "FNAME" or [FNAME]

    Your advice is working. But another problem has arisen. I had coded my subform so that if I double click on any field on the subform the corresponding name & address will be transferred to the main form. Now this is working only when linking is on LNAME. When linking is on FNAME it doesn't work. Please guide me as to what I should do. I have attached a db to demonstrate it.
    Attached Files Attached Files

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    try putting me.refresh at the end of MoveToMain()
    I'm not getting what you're trying to do or why you're doing it. The data for the subform and main form is in the same table. Cannot see why you need a subform at all. They are meant for situations where you have one record (tblOrders.OrderNumber) related to many records (tblOrderItems.OrderNumber) - not when names and addresses exist in the same record in one table. You probably should check out some tutorials on subforms.

  9. #9
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by Micron View Post
    try putting me.refresh at the end of MoveToMain()
    I'm not getting what you're trying to do or why you're doing it. The data for the subform and main form is in the same table. Cannot see why you need a subform at all. They are meant for situations where you have one record (tblOrders.OrderNumber) related to many records (tblOrderItems.OrderNumber) - not when names and addresses exist in the same record in one table. You probably should check out some tutorials on subforms.

    The CR NO is the receipt no. If the same person comes again instead of typing his details they can be got from the record. This is the purpose of the subform. Now, when in a new record we type the LNAME it shows the corresponding records in the subform and when we doble click on the field in the subform it tranfers the corresponding details to the main form. But the problem is that when in a new record we type FNAME it shows corresponding details in the subform but when we double click on the field of the subform it does not transfer the details to the main form.

  10. #10
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Still no subform required for what you describe. Other methods would be
    e.g. have unbound combo or listbox on main form. When on new record, select the CR or whatever. Details get populated.

  11. #11
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by Micron View Post
    Still no subform required for what you describe. Other methods would be
    e.g. have unbound combo or listbox on main form. When on new record, select the CR or whatever. Details get populated.

    Thanks for your advice. GOD BLESS YOU!!!

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

Similar Threads

  1. Replies: 2
    Last Post: 07-26-2018, 10:28 AM
  2. Replies: 1
    Last Post: 09-29-2016, 08:40 AM
  3. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  4. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  5. Replies: 0
    Last Post: 03-04-2011, 10:28 AM

Tags for this Thread

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