Results 1 to 5 of 5
  1. #1
    tsn.s is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Location
    Selby, North Yorkshire, UK
    Posts
    19

    Adding new record to subform on main form load


    Hi

    I am trying to add a new record to a sub form when the main form is opened via a button on a menu. I have a similar function on another form, but this is just adding a new record to the main form when it is opened by a button on a menu. After much experimenting I still haven't been able to create a piece of code that adds a new record to a sub form when the main form is opened. Any help is much appreciated. Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would expect you could use the same method that worked for you, adjusting for the subform. What did that code look like? Personally, I would normally add a record to the underlying table, and requery the form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tsn.s is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Location
    Selby, North Yorkshire, UK
    Posts
    19
    Thanks for the reply pbaldy. This is the code I have for my other form:
    Code:
    Private Sub cmdNewLearner_Click()
    
        DoCmd.OpenForm "main_learner_form", acNormal, "", "", , acNormal
        DoCmd.GoToRecord , "", acNewRec
    
    
    End Sub
    When I change it to try and refer to the sub form it tells me that the form doesn't exist.

  4. #4
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56
    This is how i open my forms

    Private Sub openformcmd()
    DoCmd.OpenForm "Protocol", acNormal, , , acFormAdd

    DoCmd.GoToRecord acDataForm, "Protocol", acNewRec
    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    GoToRecord lets you specify the form, but you have to use the syntax for a subform:

    Forms Refer to Form and Subform properties and controls
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 11
    Last Post: 02-13-2012, 10:06 AM
  2. Replies: 13
    Last Post: 01-29-2012, 01:45 PM
  3. Replies: 2
    Last Post: 12-07-2011, 02:51 AM
  4. Replies: 5
    Last Post: 11-11-2011, 11:06 AM
  5. Replies: 1
    Last Post: 10-13-2010, 12:40 PM

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