Open new record on form load fails

dab1477

Board Regular
Joined
Jul 30, 2002
Messages
65
Thanks in advance for the assist. Pulling my hair out!
I am trying to run the following code during Form Load:

Private Sub Form_Load()
DoCmd.GoToRecord acDataForm, SOC_Enter, acNewRec
End Sub

I entered the above code via the Properties/Event/On LOAD using Code Builder.

When I save and attempt to run I get a macros window asking me to enter a macro name and create the macro. I did this and no luck,


I am within an event procedure where I selected CODE BUILDER. I have saved file, exited, and returned. I get the following error:

"The expression ON_LOAD you entered as an event property setting produced the following error: Invalid outside procedure"

I have reviewed the HELP button without success. Where am I going wrong! How do I get this form to open to a new record?

Thanks.
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
If you always want to open a form to a new record, go to its Properties and change Data Entry to Yes.
If you want to open to a new record, and you are opening from a different location (eg a Command button on another form), use an event on the other form to run the DoCmd.OpenForm... line.

Denis
 

dab1477

Board Regular
Joined
Jul 30, 2002
Messages
65
BINGO! Winner, Winner, chicken dinner. You da man. Thanks Sydney. Data entry to YES worked.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,334
Messages
5,624,089
Members
416,010
Latest member
NJT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top