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.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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
 
Upvote 0
BINGO! Winner, Winner, chicken dinner. You da man. Thanks Sydney. Data entry to YES worked.
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,236
Members
448,555
Latest member
RobertJones1986

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
Back
Top