VBA code to open MS Access form to new, blank record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Will M
    New Member
    • Nov 2011
    • 2

    VBA code to open MS Access form to new, blank record

    I saw this question elsewhere on this site, but it was five years old, so I'm asking anew . . .

    I want to open a form in Access 2007 (on WinXP) by clicking a button on a different form, and I want the form to open with blank fields, to create a new record in the underlying table.

    My code is as suggested in the five-year-old posting, but it doesn't work:

    Code:
    Private Sub btnSetNewGroup_Click()
      DoCmd.OpenForm "frmGroupBasics", , , , acFormAdd
    End Sub
    What happens is that the form opens to the first record in the table, with the first field highlighted.

    Any ideas what's lacking?
    Last edited by NeoPa; Nov 18 '11, 08:39 PM. Reason: Added mandatory [CODE] tags for you
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    #2
    try this in On load
    Code:
     DoCmd.GoToRecord , "", acNewRec

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      The only thing I can think might be happening (as using acNewRec is similar to what you've already tried with acFormAdd) is that the design of the form might be set not to allow these options. You should check the property = AllowAdditions.

      Comment

      • Will M
        New Member
        • Nov 2011
        • 2

        #4
        Thanks! I was thinking I needed to specify the new, blank record from the calling control -- didn't think of putting it in the form being opened.

        Comment

        Working...