Results 1 to 2 of 2
  1. #1
    moodhi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    12

    Subform entry beofore Mainform

    This question has been asked before and I tried searching for an answer for this but could not find much!



    I have a Main form to create Employees with EmployeeID as the PK. The EmployeeID is generated in the BeforeUpdate event after all validation is complete.
    I also have a Subform to create a number of Roles for the Employee, so 1 to many relationship.
    I want to prevent creation of Mainform record until at least 1 Roles record is created.

    I tried adding code in the mainform AfterInsert event to read the Roles table to check for an entry for the new Employee record created (with newly generated EmployeeID). If not found then display message. This kind of OK but the mainform record is already saved. What I need is an event so that before the final mainform save (i.e. moving to next or before record) it will check record existence in the Roles table and prevent mainform update until at least 1 Roles record is created.

    Any suggestion please?

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,991
    What you have found is by design.
    You can't add a record to the secondary (many) table using your form/subform until it exists in the primary table.

    If its an issue, you could always delete the record when the form is closed if no record exists in the secondary table.
    But that will mean having to start again if you want to add that employee in the future.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Search subform from mainform
    By ittechguy in forum Programming
    Replies: 70
    Last Post: 10-04-2015, 06:08 AM
  2. Replies: 3
    Last Post: 09-27-2013, 11:50 AM
  3. Replies: 1
    Last Post: 11-07-2012, 05:31 PM
  4. Replies: 4
    Last Post: 03-30-2012, 01:47 AM
  5. Replies: 1
    Last Post: 11-29-2011, 01:37 AM

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