Solved New Record Button using Code

Bean Machine

Member
Local time
Today, 07:56
Joined
Feb 6, 2020
Messages
102
Hi Everyone! Very simple question I'm sure but I can't seem to find a good answer wherever I look. I want to be able to click a button and be brought to an empty new record when it is clicked, I know how to use macros to do it but I would prefer code as I am attaching some other functionality to it later. I have tried the "Me.NewRecord" function but I may not be using it correctly as it does not seem to work for me. Thanks for any help!
 
Look at

DoCmd.GoToRecord
 
Look at

DoCmd.GoToRecord

Command worked perfect thanks! Here's what I did to click the button and bring up a new record:

DoCmd.GoToRecord , , acNewRec

This is in the On Click property
 
If this is a button on the form to be cleared, another option is to use:

SQL:
    DoCmd.Close
    DoCmd.OpenForm "frmForm", acNormal, , , acFormAdd, acDialog

This allows the form to run through its On Open and On Load routines again, resetting control states, running other code, etc. Plus, I like the visual feedback it gives to the user of literally dumping the form and getting a new one.

And there is another difference. DoCmd.GoToRecord acNewRec will go to a new record in the current form, just like starting entry at the bottom of a table. This means it retains all current records in its record set. OpenForm acFormAdd will give you the form with no records in it, using the fewest possible resources. If you don't intend to use the navigation buttons to cycle through records in the form (I disable them), I recommend this method. I also recommend this if you also plan to house the back end of the database on a network that will see performance change over the course of the day due to traffic.
 
If this is a button on the form to be cleared, another option is to use:

SQL:
    DoCmd.Close
    DoCmd.OpenForm "frmForm", acNormal, , , acFormAdd, acDialog

This allows the form to run through its On Open and On Load routines again, resetting control states, running other code, etc. Plus, I like the visual feedback it gives to the user of literally dumping the form and getting a new one.

And there is another difference. DoCmd.GoToRecord acNewRec will go to a new record in the current form, just like starting entry at the bottom of a table. This means it retains all current records in its record set. OpenForm acFormAdd will give you the form with no records in it, using the fewest possible resources. If you don't intend to use the navigation buttons to cycle through records in the form (I disable them), I recommend this method. I also recommend this if you also plan to house the back end of the database on a network that will see performance change over the course of the day due to traffic.

Sounds pretty promising. There are going to be plenty of records so the "next record" functions are almost pointless. I also like that this would reduce the amount of work being done in the background. I appreciate the detailed and highly useful advice! I certainly think I'll use "acFormAdd". Thank you!
 

Users who are viewing this thread

Back
Top Bottom