Answered by:
Adding Second Record Causes "You Cant Go To The Specified Record" Error.

Question
-
I have an "Add Record" button on a form that when pressed does "DoCmd.GoToRecord , , acNewRec" and adds a new record.
This works correctly the first time it is pressed.
However, if the button is immediately pressed again to create a second record the error "Run-time Error '2105': You Cant Go To The Specified Record" is encountered.
Allow additions for the form is set to Yes.
The recordsource of the form is a table not a query, so isn't read only.
The Recordset Type is Dynaset
Nath
Monday, June 5, 2017 11:40 AM
Answers
-
Thanks for you help.
The solution to this though, ended up being as simple as having "Me.AllowAdditions = True" before the "DoCmd.GoToRecord , , acNewRec" line.
Nath
- Marked as answer by NaPazz Wednesday, June 7, 2017 1:59 PM
Wednesday, June 7, 2017 1:59 PM
All replies
-
Hi Nath, Sounds like you haven't saved the new record yet. Try adding DoCmd.RunCommand acCmdSaveRecordMonday, June 5, 2017 12:35 PM
-
Hi.
Here is the code I have on my Add button:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , , acNewRec
When the button is pressed once, a new record is created. However, when the button is immediately pressed a second time the error: Run-time error '2105': You Can't go to the specified record. still occurs at the DoCmd.GoToRecord , , acNewRec line.
Nath
Monday, June 5, 2017 1:01 PM -
Hi Nath,
When you press the button, the record pointer goes to a new record. If you press it again without doing anything else in between, then the record pointer is still on the new record, so Access can't go anywhere else, which is why you're probably getting an error.
Maybe you could add an If statement to check if you're already on a new record and then don't do anything. For example:
DoCmd.RunCommand acCmdSaveRecord
If Not Me.NewRecord Then DoCmd.GoToRecord , , acNewRec
Hope it helps...
Monday, June 5, 2017 4:34 PM -
When the button is pressed once, a new record is created.
Wrong; the form merely moves to an empty new record position, it does not even initiate a new record. Once this is understood, it is clear that the behaviour you are experiencing is inevitable. Once you've moved to an empty new record position, you can't then *immediately* move to an empty new record position, as you are already at it. Attempting to save the record first will do nothing as there is nothing to save. This is true even if one or more of the columns have default values. Until the user begins to insert other data, or edits one of the default values, no new record has been initiated, so again there is nothing to save.
Ken Sheridan, Stafford, England
- Edited by Ken Sheridan Monday, June 5, 2017 4:48 PM Emphasis added.
- Proposed as answer by Deepak Saradkumar PanchalMicrosoft contingent staff Tuesday, June 6, 2017 1:05 AM
Monday, June 5, 2017 4:43 PM -
Thanks Ken.
What can I do to automatically get the Add New Record Button at a point where it will work on an immediate second press.
e.g. automatically update a field and save the new record?
Nath
Wednesday, June 7, 2017 9:27 AM -
If a control in the form has a DefaultValue set then you can assign the value to the control in the form's Current event procedure, e.g.
If Me.NewRecord Then
Me.Department = Me.Department
End If
Otherwise you can assign a literal value to any control, e.g.
If Me.NewRecord Then
Me.Department = "Sales"
End If
Either will Dirty the form, so when you move off the form to another new record it will be updated.Ken Sheridan, Stafford, England
Wednesday, June 7, 2017 11:14 AM -
Thanks for you help.
The solution to this though, ended up being as simple as having "Me.AllowAdditions = True" before the "DoCmd.GoToRecord , , acNewRec" line.
Nath
- Marked as answer by NaPazz Wednesday, June 7, 2017 1:59 PM
Wednesday, June 7, 2017 1:59 PM -
Hi Nath,
Congratulations on finding a solution. Good luck with your project.
PS. If AllowAdditions was False before clicking on the button, you might consider setting it back to False after the GoToRecord acNewRec line. Just a thought...- Edited by .theDBguy Wednesday, June 7, 2017 2:34 PM
Wednesday, June 7, 2017 2:32 PM