Automatically Moving to the Last Record When You Open a Form in Access 2007

Microsoft Access, Tips & Tricks Add comments

Microsoft Access tutorial tweakData entry in Access is often a “What have you done for me lately?” affair. That is, when you open a form, you often display the most recently entered record, which can help you get your bearings for entering more records. In most forms, you display the most recently entered record by moving to the last record, which you can do by clicking the Last Record button (or by choosing Home, Go To, Last). If you always do this when you open a partic­ular form, you can save yourself a step by configuring the form to always automatically move to the last record.

To understand how to do this, you need to know that when certain actions occur in Access, the program fires an event, which is just a programmatic indication that the action has occurred. For example, when you navigate to a new record in a form, Access fires the Current event because the form now has a new current record. For any event, you can use VBA to create an event handler, a procedure that runs each time its associated event fires. For the current event, for example, your event handler can move the focus to a particular field.

For our purposes in this section, we want to take advantage of the Open event, which fires each time you open a form. In this case, we use the Open event handler to automatically move to the last record. Here are the steps to follow:

  1. With the form open in Design view (right-click the form in the Navigation pane and then click Design View), choose Design, Property Sheet to open the Property Sheet pane.
  2. In the Selection Type list, click Form.
  3. Click the Event tab.
  4. Click inside the On Open property, and then click the … button. Access displays the Choose Builder dialog box.
  5. Click Code Builder and then click OK. The Visual Basic Editor and the basic code for the Open event handler display
  6. Private Sub Form_Open(Cancel As Integer)
    End Sub

  7. Between the Sub and End Sub statements, type the following statement code (where form is the name of your form; see Figure 1):
  8. DoCmd.GoToRecord acDataForm, “form”, acLast

  9. Choose File, Close and Return to Microsoft Office Access.

The next time you view the form, Access automatically navigates to the last record.

Use the Open event han­dler to configure the form to automatically navigate to the last record when you open it
Figure 1 Use the Open event han­dler to configure the form to automatically navigate to the last record when you open it.

TIP

If you have a form where you always start a new record for data entry as soon as you open the form, you can use the Open event handler to automatically start a new record for you. Follow the steps in this section, and in Step 6, add the following statement (again, where form is the name of your form):
DoCmd.GoToRecord acDataForm, “form”, acNewRec

Technorati Tags: , ,

Popularity: 9% [?]

Related Post

  • Creating a Switchboard Form in Access 2007
  • Opening a Form Automatically When You Load a Database in Access 2007
  • Preventing Changes to the Form’s Data Source in Access 2007
  • Using a Form in Windows Vista
  • The Form Wizard in Access 2007
  • Don't Find What You're Looking For? Please Try Here...

    Google
     

    3 Responses to “Automatically Moving to the Last Record When You Open a Form in Access 2007”

    1. Peter Says:

      Careful of the smart quotes..

    2. cwxwwwxdfvwwxwx Says:

      well, hi admin adn people nice forum indeed. how’s life? hope it’s introduce branch ;)

    3. Engerse Says:

      wathc .it contain tickets to detroit .lynx international airlines which contains all of the midwest airlines center Ok, here cheapest airfare Here ticket to usa santa maria horizon airlines , flights from san luis obispo califonia to las vegas nevada In image as .Links lowest airfare available the need for You search here which contains all of the helicopter charter flight new zealand which contains all of the .and this is the best resource on cheap tickets from dc .airline travel articles about yorkies as a result of student discount plane tickets follow discount air fare to cancun The flights to cardiff as a result of last minute cheap airline tickets .

    Leave a Reply

    WP Theme & Icons by N.Design Studio
    Entries RSS Comments RSS Add to Technorati Favorites Log in