Results 1 to 7 of 7
  1. #1
    pdlecesne is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2013
    Posts
    12

    Adding New Record to Subform Not Working

    I have two tables, one for Member Demographics, one for Member details. A Member can have up to three terms. Each term is for two years and has it's own contract. The Relationship has been built to link on member #. Member #is the PK in the Demographic Table. Contract # is the PK in the Detail table. I created a subform linking the details to a Parent Demographic table. I then tried to add a "Add New Contract" to the subform (BOARD_DETAILS1) that would open a blank entry in the subform. The Code is below

    Private Sub btnAddNewContract_Click()


    Me![BOARD_DETAILS1].SetFocus


    Me.AllowEdits = True
    DoCmd.GoToRecord , , acNewRec
    End Sub

    I keep getting the following error when clicking the button created.
    Click image for larger version. 

Name:	accesserrormessage.PNG 
Views:	18 
Size:	15.6 KB 
ID:	26602

    I only want the user to be able to add to the contracts table (Board Details) if they select the add new contract button.

    Please help.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    You don't really need code to make new records.
    if you have a master /child form, you'd just add records on the form.
    but
    the master record must be saved in order to add sub recs.
    the sub table must be keyed to allow many sub records. The wrong key structure will prevent adding.
    the master/child form must be linked on the master field to add sub records.

  3. #3
    pdlecesne is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2013
    Posts
    12
    Thanks. I thought I had already done this but maybe I missed something. I am attaching pictures of the relationship between the tables as well as the design of the form. Can you identify what I may have missed?

    Click image for larger version. 

Name:	MSOW Relationships.PNG 
Views:	10 
Size:	35.5 KB 
ID:	26607Click image for larger version. 

Name:	design view of form and subform.PNG 
Views:	10 
Size:	61.4 KB 
ID:	26608

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In addition to AllowEdits = True, you must also have AllowAdditions = True.

  5. #5
    pdlecesne is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2013
    Posts
    12
    Thanks, I actually do not want to allow edits without selecting the 'Edit button' as I do not want the end user to accidentally change the details. ( It happens quite often in our organization). I am trying to get to the point of creating my own navigation buttons and will 'turn off' the default ones to prevent their use. I created a Edit Button for this purpose--- do I need the add button to reference the edit button in order to get the record added? If so how would I do that?

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Have the "Add" button turn both AllowEdits and AllowAdditions on, and have the "Edit" button turn on only AllowEdits.

    What you'll need is a way to turn them off again - maybe something in the On Current event to turn them off if it is not a new record.

  7. #7
    pdlecesne is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2013
    Posts
    12
    Thanks! Me.AllowEdits and Me.AllowAdditions before the Docmd function worked great!

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

Similar Threads

  1. Replies: 21
    Last Post: 10-19-2015, 05:38 PM
  2. Replies: 6
    Last Post: 08-22-2012, 03:24 AM
  3. Replies: 14
    Last Post: 05-25-2012, 02:40 AM
  4. Replies: 4
    Last Post: 03-14-2012, 10:08 AM
  5. execute code on subform without adding a record
    By markjkubicki in forum Forms
    Replies: 5
    Last Post: 10-13-2011, 12:23 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