Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open A Form To Automatically Go To Add A New Record

Status
Not open for further replies.

mas5

Programmer
Dec 15, 2002
98
US
I would like to Open a Form to automatically go to open a new record so the user won't have to know to press the * at the record selector. I have a form (FORM1) where they either select a specific record to edit or they select add a new record. When they pick the add a new record function I want to go to a new record on FORM2. I've tried various different ways of using:

Docmd.Openform stformname , acnormal, etc.

but can't seem to get the syntax right. I tried acformadd in the DataMode, but that didn't work properly for me since the form I want to open is a main form with a subform and the subform is where I want to add the new data. With acformadd in the DataMode it thinks I want to add a new main form record, but that isn't what I want.

I've also tried to put code in the oncurrent event of the subform that I open. I tried if the selection option from FORM1 is add a new record then

docmd.gotorecord,, acnew

and it appears that I have a new record (the fields are blank) but somehow the very first record in my file is lurking under there. I have validation logic in my form that confirms any changes the user makes to the record and this validation logic kicks in. The very first record of my form is somehow lurking under all this - it seems I go to newrec and then I go back to the first record.

Any ideas of how to fix/address this problem?

Thanks for your help.
 
1) use the command button wizard to add a button to "Add a New Record".
2) Move the code to the FORM_OPEN event

Delete the button from the form.

OR

DoCmd.OpenForm "YourFormNameHere", , , , acFormAdd

JMH

Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
There is a marco in Access can do this.
At the "From View", select the (the left bar)
Select "Properties",
Just go to "Event",
on "On load" chooses "Marco Builder", name the marco, on the "Action" field, chooses "GoToRecord".
At the bottom of the windows, in the "Record" field, chooses the "New". That is!
 
Thanks saieyo. You led me in the right direction. I moved the logic I had in my oncurrent event of my subform to the load event of my subform and it solved my problem.

JMH - I had already tried your suggestion - my problem was that I wanted to advance to the newrecord within a subform, not a mainform, and that logic didn't work because of that. But, thanks for your suggestion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top