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

Open a form showing last record entered

Status
Not open for further replies.

dalex17

Technical User
Jul 14, 2002
96
US
How do I default a form to show the information of the last record that was entered from a previous form? For example. I have a list of names on form1. When I enter a new name on this form1, and click next, I would like form2 to display the last name that I created on the previous form1. Please let me know if I should clarify my question.

Thanks,
 
Hi

Easiest way to do this is to set the filter within the DoCmd.OpenForm, which you are using to open form 2, to the unique value which identifies the record you wish to open,

DoCmd.OpenForm ...blah, "MyId = " & Id ,...blah Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
In the 'Load' event of the form add the following code and it will always open at the last record of the recordset. I assume this is what you want:-


Private Sub Form_Load()
DoCmd.GoToRecord acDataForm, "name of your table", acLast

End Sub

HTH

Dave
 
Hi

Please note using:

DoCmd.GoToRecord acDataForm, "name of your table", acLast

will take you to the last record, in key sequence or the recordset, this may or may not be the last record entered.

Consider the situation where Id is the Prime key, and recordset is ordered by Id, if you have (existing) Id's 5 and 10, then add 1 and golast, you will position on 10, not 1 Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi

Please note using:

DoCmd.GoToRecord acDataForm, "name of your table", acLast

will take you to the last record, in key sequence of the recordset, this may or may not be the last record entered.

Consider the situation where Id is the Prime key, and recordset is ordered by Id, if you have (existing) Id's 5 and 10, then add 1 and golast, you will position on 10, not 1 Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Grumbledook's advice is what I needed...thanks.

I also appreciated KenReay's advice. It may prove valuabe when I am further along with my project.

Thanks again!
 
Hello Grumbledook,

When I apply your code, I get the error message: "The object "table name" isn't open". Any ideas? Does the table need to be open in order for the code to work. I will appreciate any advice. thanks!
 
Actually in a form, you are right, this wouldn't work:
DoCmd.GoToRecord acDataForm, "name of your table", acLast

It should be:
DoCmd.GoToRecord acDataForm, "name of your form", acLast
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top