Results 1 to 5 of 5
  1. #1
    pncbiz is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2020
    Location
    Maryland
    Posts
    66

    Force subform linked to unbound master form to new record

    First, I just want to say - thanks to everyone who has helped me on my project over the last few weeks. You've been amazing and I have learned so much. When I started, I wanted to use macros exclusively because I didn't think I had the time to learn VBA. Now, I'm completely the opposite. Much prefer to use VBA over macros because the macros seem to be 1) limited and 2) unpredictable. I've made incredible progress on my own because of what I've learned here.

    I have one more critical dilemma and can't figure how to solve it. I have an unbound main form with multiple subforms. In the top subform, the user can select the contract they want to view/edit. In the next subform, the details of the subform are displayed. It's kind of like a split form; datasheet view on top, single form view on the bottom. There's a third subform at the bottom listing the products associated with the selected contract. All of that works beautifully. I've even incorporated copy buttons that copy the contract or product and all the related records.



    My problem is adding a new contract. Since the main form is unbound, the selector subform populates a hidden text box on the main form. I then have the details subform Parent/Child linked to that hidden control. I want the user to be able to add contracts from the same form, but I can't get a command button to work. I tried

    Code:
      DoCmd.GoToRecord acDataForm, "subOrder", acNewRec
    in a command button (subOrder is the name of the subform where you enter the contract details), but the button errors out and says the form isn't open (clearly it is). I'm guessing the problem is the Parent/Child relationship (can't drive the Child to a record out of sync with the Parent). Is that right? If so, how do I over come that? I guess I could push the new record into the selector form, which would then cascade to the subOrder form, but I don't want users to enter new contract data in the selector form, so I have additions/edits turned off. Any thoughts?

    Thanks,
    Phil

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    it's because it is a subform. Not sure how you would do that from another subform as such

    suggest move the focus to the subform, then gotorecord, leaving the first two parameters blank. Code might look something like

    parent.sfSubOrder.setfocus
    docmd.gotorecord ,,acNewRec

  3. #3
    pncbiz is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2020
    Location
    Maryland
    Posts
    66
    Thanks, Ajax!

    So that worked to take the subform to a new record, but now the subform is out of sync with the rest of the subforms. Don't know how to fix that...I'm going to plug away at it a little longer, unless someone has an alternative approach to offer.

  4. #4
    pncbiz is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Jul 2020
    Location
    Maryland
    Posts
    66
    As I think about this more, it may be time to create a popup...that would get the new record entered, then I could set the selector form to that record's ID, which would drive the rest of the form....

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

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

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2019, 08:14 AM
  2. Replies: 1
    Last Post: 03-16-2017, 10:16 AM
  3. Replies: 9
    Last Post: 11-21-2014, 07:06 PM
  4. Linking Subforms on Unbound Master Form?
    By 10 Gauge in forum Forms
    Replies: 8
    Last Post: 07-21-2011, 08:06 AM
  5. subform to open form w/ active master record
    By spitfire122 in forum Access
    Replies: 1
    Last Post: 06-28-2011, 04:28 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