How can I resolve runtime error 2105 "can't go to specified record" occuring on some records but not others

conardb
conardb used Ask the Experts™
on
How can I resolve runtime error 2105 "can't go to specified record" occuring on some records but not others.  I have a subform where the onclick event of the id field opens a details form using code below:  Existing records on the subform open.  New records that I've added return the rt 2105 "can't go to specified record"?  eventhough the records exist and the id is correct.

If IsNull(Me.ID) = True Then
    DoCmd.OpenForm "Task Details", acNormal, , , acFormAdd
    DoCmd.GoToRecord acDataForm, "Task Details", acNewRec
    Forms![Task Details].CaseID = Me.CaseID
Else
    DoCmd.OpenForm "Task Details", acNormal
    DoCmd.GoToRecord acDataForm, "Task Details", acGoTo, Me.ID
    ', acFormAdd, , OA
End If
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DoCmd.OpenForm "Task Details", acNormal, , , acFormAdd
    DoCmd.GoToRecord acDataForm, "Task Details", acNewRec

These statements are both trying open a new record.
You don't need the second one.

Author

Commented:
I commented out one of them with no affect.

The error is occuring on the else selection but only for records that have recently been added and are in the underlying table.  It is not returned for previously entered records that are in the underlying table.
DoCmd.GoToRecord  acDataForm, "Task Details", acGoTo, Me.ID

This is extremely unlikely to be a logically valid command.
It is correct in terms of syntax but won't be doing what you expect.

It is moving to the record position denoted by the value in the ID field.

For example , if ID contains 17, the the command moves to the 17th record in the form's recordset.  That is not the same as moving to the record whose ID is 17.  The 17th record could have ID 466666 or there might not be a 17th record.  Judging from your error message you are hitting the case where the xth record does not exist.

To open the form on a specific record you do...

 DoCmd.OpenForm "Task Details", acNormal,,"ID=" & me.ID

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial