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

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
conardbAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peter57rCommented:
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.
0
conardbAuthor 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.
0
peter57rCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.