By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,224 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,224 IT Pros & Developers. It's quick & easy.

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

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSetNewGroup_Click()
  2.   DoCmd.OpenForm "frmGroupBasics", , , , acFormAdd
  3. 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?
Nov 18 '11 #1

✓ answered by neelsfer

try this in On load
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.GoToRecord , "", acNewRec

Share this Question
Share on Google+
3 Replies

P: 547
try this in On load
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.GoToRecord , "", acNewRec
Nov 18 '11 #2

Expert Mod 15k+
P: 31,707
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.
Nov 18 '11 #3

P: 2
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.
Nov 22 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.