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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last Record Problem 1

Status
Not open for further replies.

Wrecker

Technical User
Aug 29, 2001
126
US
I have a form that the "Last record" button stopped working properly. It is not going to the last record when the buton is pushed. It stops about 20 records up in the table. I think it is sorting on another field. How do I tell it to use the "ID" field (Primary Key) for the last record?

Thanks
Wrecker
 
The Last record entered in the database.

Private Sub Last_Record_Click()
On Error GoTo Err_Last_Record_Click


DoCmd.GoToRecord , , acLast

Exit_Last_Record_Click:
Exit Sub

Err_Last_Record_Click:
MsgBox Err.Description
Resume Exit_Last_Record_Click

End Sub
 
Dear Wrecker,

You probably are using a table as a record input source, so the last record will be whatever the table returns as last base on the primary key and sequence used.(Assuming no temporary sequence or filters are active)

If you want the records in a certain sequence, create a query and sort on the field(s) of your choice. Now last record will work correctly.

Note: If you do this, and you add a new record, this will become the last record until the form closes. If this is an issue, then when you add a new record, place this line of code:
Me.Requery
in the After Insert event of the form.

Hope This Helps,
Hap [2thumbsup]


Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
Wrecker,
While human brain understands perfectly the notion of 'last record entered in the database', database intelligence does not go so far. First record, last record, middle record, what difference does it make? A record is a record and nothing else. Therefore you -the developer-need to provide the database with a tiny piece of info to define the notion.

It is a (bad) habit to have an incremental AutoNumber as key to find the last record. And most of the users are surprised when it fails. That's because AutoNumber does not assure a continuous - or ordered - sequence of numbers to rely on. All AutoNumber does is to create arbitrary unique numbers. If set to Increment, it tries to keep an ordered sequence.

A better way is to have a time stamp field, set to Now() when record is saved (AfterInsert event).
Best way is to create your own numbering system to number the records when they are created. Do a search on the forum for information on how to do it.

Last, but not least, you have a form. The form can be sorted in various ways.
GoToLastRecord will go to the last displayed record, not to the last entered...

And...just to make sure I didn't get it totally wrong:
Do you mean that the cursor does not go to the last displayed record, but somewhere in the middle of the form, about 20 records before the end???
Never heard of that...if that's the case, you're probably facing some code corruption...

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
Still confused. I am using a Form to input data into the table. I have several databases designed the same way and they work fine. When the form opens I have the code set to go to the last record entered by the user. The user also has a record navigation button used to go to last record if they navigate back and forth (Last record , Previous record). The problem is the records no longer seem to be in order. When viewed using the form, they are not in order, but they are in order when viewed in the table.

Thanks
Wrecker
 
As I said, a form can be sorted in various ways.
When you notice a 'funny' order in the form, just display it in Design View and check its OrderBy property.

Another thing to check: is the recordsource of the form the table or a query/SQL statement?
If the latter, the order on the form is given by the order in the query.

HTH

[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top