Run-time error '2105' - can't go to the specified record (1 Viewer)

AccessChap

Registered User.
Local time
Today, 09:24
Joined
Apr 14, 2009
Messages
32
Hi guys,

I've got (yet another) weird error on my inherited database. I have a form with the standard navigation buttons in the footer (first record, prev record, next record, last record & new record). When using these to navigate to record 3816 there is no error. However when using a few VBA commands I get the above error message, even though I'm navigating to a record that does exist and can be loaded using the standard navigation buttons :(

On this form I have a couple of list boxes, both of which have the OnDoubleClick event set to fire off the GoToRecord command. Even stranger, this one works:

...
Request = OpenCall_OnHold.Value
DoCmd.GoToRecord , , acGoTo, Request
...

but this code fails with error 2105:

...
Request = OpenCall_Amend.Value
DoCmd.GoToRecord , , acGoTo, Request (debugger steps in here)
...

I have set a trap on the same line of both instances of the code and found that acGoTo is set to 4 on both with the correct record ID being shown in each case

Given that I have two instances of the same code on the one form but they behave differently I am a little confused... Anyone have a suggestion or some advice on how to diagnose this issue? All help gratefully accepted at this stage!

Cheers,

Andy
 

SOS

Registered Lunatic
Local time
Today, 01:24
Joined
Aug 27, 2008
Messages
3,517
What record ID are you using? It would be the primary key of the recordset, not the record count number. The record count number is meaningless and can change for each record each time you open the form. The record number is basically just a relative number to show approx where you are in your recordset. And it is good only for the session you have open. So record number 3816 this time you have the form open may be record 3522 next time.

So, I would use the FIND feature and use the primary key of the recordset to find the record. That is more reliable.
 

AccessChap

Registered User.
Local time
Today, 09:24
Joined
Apr 14, 2009
Messages
32
Thanks for the reply, I'm in a different office today so I'll have to check this out tomorrow. What you have said does make sense though (re session only IDs) so I'll have a look at the find command and keep you posted

Cheers,

Andy
 

AccessChap

Registered User.
Local time
Today, 09:24
Joined
Apr 14, 2009
Messages
32
OK, I managed to get back early and I've had a look at your comments and reviewed my code. I see what you're saying now. The GoToRecord command actually uses my submitted value against the record count and not the table's primary key :( Looks like I have some code to correct because although I am submitting the correct primary key value I need a function that actually uses the primary key to jump to a record

I can't find any help on a Find command, would you have an example snippet of code to give me some context please? I'm sure it's just the way I'm searching the help but I'm drawing a blank

Many thanks,

Andy
 

SOS

Registered Lunatic
Local time
Today, 01:24
Joined
Aug 27, 2008
Messages
3,517
Basically something like this:
Code:
    ' Find the record that matches the control.
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[testID] = " & Str(Nz(Me![Combo11], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark

It uses a bookmark but only if it finds something. This goes through the form's recordset using the recordsetclone and then moves to that particular record if it finds one. If it doesn't then it won't move.
 

AccessChap

Registered User.
Local time
Today, 09:24
Joined
Apr 14, 2009
Messages
32
Cool, thanks for that. Database is working much better now :)
 

Users who are viewing this thread

Top Bottom