Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Go to the firts record (Access 2000)

    How can i begin from the first record?


    I have a table customers and on opening it i have the following event:
    DoCmd.GoToRecord , "", acNewRec
    DoCmd.GoToControl "customerid"



    On opening the form i go to a new record indeed.However the records begin from the last record, and i am forced to move to the left
    if i want to look at them , i have to go back. Is it possible to go to a new record in the same time begin moving to the right direction,
    beginning from the fist record?

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Go to the firts record (Access 2000)

    I'm <img src=/S/confused.gif border=0 alt=confused width=15 height=20> - when you open a form and begin an insert by going to a new record, it gets appended after the last record. If you want to go to an existing record, then you can't add a new record. One scenario is to make a copy of your form and set the DataEntry property to True. When you open that form you will only see new records, never old ones. If you want to see existing records then you would open the original form, but you would disallow adding new records on that form. But I suspect that's not what you want to do, so can you give us a bit more explanation as to what to do please?
    Wendell

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Go to the firts record (Access 2000)

    It sounds like your form is based directly on the table. Instead build a query that selects all fileds, but sorts into the reverse order. Make this query the record source for the form.
    Regards
    John



  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Go to the firts record (Access 2000)

    Are you talking about records displayed in a single form? When you use DoCmd.GotoRecord and pass it the acNewRecord argument, you will automatically be positioned at the new record row, which is always the last row on a continuous form or the last record in a single form using the navigation buttons. It sounds like you're using the latter arrangement, and that's just the way it works. Access records don't really have a set order, so Access always inserts new records at the end of the recordset. In a single form view, that means the last record "to the right" on the navigation buttons.
    Charlotte

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Go to the first record (Access 2000)

    As noted, new record on form always will be last record in recordset. What I do in some cases is, after saving new record, run code similar to this to move new record to its proper sequence based on sort order specified in form's underlying RecordSource:
    <pre>Private Sub Form_AfterInsert()

    'RecordID = Primary Key
    Dim strRecordID As String 'Text
    'Dim lngRecordID as Long 'Number

    With Me
    strRecordID = .RecordID
    'lngRecordID = .RecordID
    .Requery
    .RecordsetClone.FindFirst "[RecordID] = '" & strRecordID & "'"
    '.RecordsetClone.FindFirst "[RecordID] = " & lngRecordID
    .Bookmark = .RecordsetClone.Bookmark
    End With

    End Sub</pre>

    Sample sub shows alternate syntax depending on whether primary key is text or number data type. You have to first save the new record, including primary key field, to be able to resequence records in this manner. I would not know of any good way to make new record automatically appear at beginning rather than end of recordset.

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •