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

Display Last Page of Records in a Form

Status
Not open for further replies.

zevw

MIS
Jul 3, 2001
697
US
I have a form that I would like each time the form opens that it should go to the last or new record on the continuous form.

I wrote in my open event procedure

DoCmd.GoToRecord,,acnewrec
or
DoCmd.GoToRecord,,aclast

It works fine.

what happens is, it jumps to the new record, and displays that record at the top of the form.

I would like to know is there a way to go to the last/new record, and still see at least the last page of records on the screen.

Thanks for your help in advbance
 
You could start at the beginning of the table and scroll all the way through to the end. Not incredibly efficient, but it should work:

On Error GoTo Err
While (True)
DoCmd.GoToRecord acDataForm, "WhateverForm", acNext
Wend

Err:
Next


Hopefully someone has a better way ... mine is ugly as hell for large tables!

Rob

 
Ha! I love this stuff!

I just played around and got the following to work:


Put this in the form's OnOpen event.

DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acPrevious, 7

The code goes to the last record, then backs up 7 records and displays the last 7 records as you want. Change the value 7 to however many records your form accomodates prior to the last record.

Unfortunately, if your table is really big and this navigation takes a long time, I don't know how to avoid that under any circumstances.
 
ReluctantDataGuy!

I agree with you that I can go to the 7th record to do a acprevious,7. This solution will place the cursor in the seventh record, and if I want to do that I can get a recordcount, then when I open the form do a acnext, recordcount - 7.

I want the cursor should stay in the last or new record, and display on the form the last number of records that can be displayed on a form window at one time.
 
zevw, have you considered the option of sorting your records differently so that the one you want to see first is at the top instead of the bottom? I don't know how your data is currently sorted, but usually you can reverse the sort. Sometimes its easy like based on datetime or an autonumber or other key value(s).

I don't have time to try this right now, but what MIGHT work, is to use my code above and then add:

DoCmd.GoToRecord , , acNext, 7

I don't know if that will just move back down the list, leaving all the records in sight, or if it will result in just the new or last record showing. Its worth a try if you don't like the resort idea...
 
are you attempting to input the last record's data as the default value for the new record, or are you just wanting the user to look at what was entered last?... If the former, then there are several articles in here and out on the web for using the previous data as the default for a new record, and if its the latter, then one method is to open the form, go to the last record, store the values to the caption property of some labels that are in the Header or Footer section of the Form and not the Detail section and then add code to move to the new record.

PaulF
 
PaulF!

What I want is simple. When the form opens it should always open for the user to enter a new record. The problem with that is it will jump to the last row and hide all previous records on top of the form. so when you look at the form you only see the new record (which at open has no data). I would like for the form to open, the cursor should STAY in the new record, and you should still see the last number of records that can be seen on a form window at one time.

If you don't understand what I mean, if you have ever used QuickBooks the account opens the cursor is at the new transaction to enter and you see the last lets say 15 previous transactions.

If you have a real good idea, I am ready for solutions.

While waiting for an answer, I have a way to do this which is a little messy (thanks for the 2 previous responsers).get a record count and open the form and do acnext, recordcount minus 10 and then do an acnext 10 which will get me to the new record. It is a way around, but I am sure there is a way to open a form and have it in the new record and still have displayed the previous 10 records.

Thanks for your response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top