Results 1 to 6 of 6
  1. #1
    madams is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    15

    Question using subform to allow additions under certain circumstances not always working

    I have a form with two subforms and they all use the same tables.
    On one subform I always allow additions and they are many to many records.


    On the second subform I only want to allow for one to many records. Based on what option they choose when I open the form I hide/show the appropriate form. On the second subform if they open it with existing records I set Me.AllowAdditions = False because the initial record already exists and I don't want them to add a second record. If they open the form to add new records, It opens with Me.AllowAdditions = True and after they add the first record I set Me.AllowAdditions = False so they can't add a second record. It all seems to work as I intended but my problem is if they use the form control of arrows to move through the records it will move past the last record and add a new record but because Me.AllowAdditions = False the subform has no fields to enter the data because it's still on Me.AllowAdditions = False and didn't detect that it's a new record.

    Is there a way to detect that it's a new record and change Me.AllowAdditions = True?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I am confused. If you set it so user can't add a new record, why would you reverse that just becaue they used cursor keys to navigate?

    I actually cannot replicate described behavior.

    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.

  3. #3
    madams is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    15
    They still need the ability to move through the records so on the initial form the navigation buttons is set to Yes but on the subform (where I only want them to add one record the navigation buttons are set to No. So when they use the navigation buttons they are actually scrolling through the parent table on the initial form not the child table on the subform.

    They still need the ability to add a new parent record on the initial form. Is it just a matter of adding code that if they add a parent record to set me.AllowAdditions =True at that point?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    The Me.AllowAdditions code is behind subform?

    So when main form moves to new record row you need to allow subform to add record?

    Maybe:

    If Me.NewRecord Then subformcontainer.Form.AllowAdditions = True
    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.

  5. #5
    madams is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    15
    Yes, when the main form moves to a new record I need to allow the subform to add 1 new record

    Where would you place the Me.NewRecord though? On the main form under what event?

    And if they navigate off the new record without entering something in the main form I would need to reverse the AllowAdditions = True so where would I put that code because I wouldn't want to leave it in AllowAdditions = True?

    It sounds like it would be easier to check for NewRecord but what I've done so far as a workaround is I used the afterUpdate event on one of the fields on the main form to check if the subformcontainer.form.allowadditions = False and then I check to see if there's an existing record on the subform (incase they are updating an existing record) and as long as there isn't an existing record I allowadditions = true

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Yes, real trick is figuring out what event to put code into. Perhaps main form Current event. Consider:

    subformcontainer.Form.AllowAdditions = Me.NewRecord
    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.

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

Similar Threads

  1. Need to find records in special circumstances
    By Dave14867 in forum Access
    Replies: 3
    Last Post: 08-19-2019, 11:07 AM
  2. Replies: 13
    Last Post: 01-26-2018, 07:17 AM
  3. Subform data additions help
    By abbyjade99 in forum Forms
    Replies: 4
    Last Post: 08-13-2016, 05:45 PM
  4. Replies: 1
    Last Post: 01-17-2012, 02:50 PM
  5. Multi-record additions using a list box not working right
    By avarusbrightfyre in forum Programming
    Replies: 3
    Last Post: 10-27-2010, 01:50 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