Refresh & Goto Last

Discussion in 'Microsoft Access Form Coding' started by Guest, Jul 11, 2006.

  1. Guest

    Guest Guest

    Hi ,

    I have a pop up form which allows users to add a new record. When the popup
    is closed, I have a Requery run at OnClose so that the Main Form
    ("frmcypNew") is updated with the new record. This works fine.

    What I want to do is: have it so that the main form (which shares a
    recordsource with the popup) will goto the Last Record (ie the new one) when
    the popup closes.

    I have tried:
    DoCmd.GoToRecord acDataForm, "frmcypNew", acLast
    in the OnClose, Deactivate and Unload events on the popup form - nothing
    happens.

    I have tried:
    DoCmd.GoToRecord acLast
    in the GotFocus event of the mainform - to no avail - and the same in the
    Current event of the main form - This does work, but causes problems when
    trying to view any records other that the newly entered (ie makes it
    impossible).

    What code do I need and where?

    Thanks in advance
    Jim
     
    Guest, Jul 11, 2006
    #1
    1. Advertisements

  2. Guest

    Guest Guest

    In the code in the main form, open the popup form in dialog mode. The
    Docmd.OpenForm method has a parameter called WindowMode that allows you to
    open it this way. The advantage is that this code waits until the popup form
    is closed to continue executing. This allows you to do this:

    DoCmd.OpenForm "frmAddRecord", WindowMode:=acDialog
    DoCmd.RunCommand acCmdRecordsGoToLast

    The 2nd line won't execute until frmAddRecord has closed.

    HTH,
    Barry

    "Zilla" wrote:

    > Hi ,
    >
    > I have a pop up form which allows users to add a new record. When the popup
    > is closed, I have a Requery run at OnClose so that the Main Form
    > ("frmcypNew") is updated with the new record. This works fine.
    >
    > What I want to do is: have it so that the main form (which shares a
    > recordsource with the popup) will goto the Last Record (ie the new one) when
    > the popup closes.
    >
    > I have tried:
    > DoCmd.GoToRecord acDataForm, "frmcypNew", acLast
    > in the OnClose, Deactivate and Unload events on the popup form - nothing
    > happens.
    >
    > I have tried:
    > DoCmd.GoToRecord acLast
    > in the GotFocus event of the mainform - to no avail - and the same in the
    > Current event of the main form - This does work, but causes problems when
    > trying to view any records other that the newly entered (ie makes it
    > impossible).
    >
    > What code do I need and where?
    >
    > Thanks in advance
    > Jim
    >
    >
     
    Guest, Jul 11, 2006
    #2
    1. Advertisements

  3. hi,

    Zilla write:
    > I have a pop up form which allows users to add a new record. When the popup
    > is closed, I have a Requery run at OnClose so that the Main Form
    > ("frmcypNew") is updated with the new record. This works fine.
    >
    > What I want to do is: have it so that the main form (which shares a
    > recordsource with the popup) will goto the Last Record (ie the new one) when
    > the popup closes.
    >
    > I have tried:
    > DoCmd.GoToRecord acDataForm, "frmcypNew", acLast

    The new record is not necessarily the last record.

    > What code do I need and where?

    If you have an unique ID you can use the following function:

    Public Function FormRequery(AForm As Access.Form, _
    Optional AID As Long = 0 _
    ) As Boolean

    On Local Error Resume Next

    Dim ID As Long

    If AID = 0 Then
    ID = AForm![ID]
    Else
    ID = AID
    End If

    AForm.Painting = False
    AForm.Requery
    With AForm.RecordsetClone
    .FindFirst "ID = " & ID
    If Not .NoMatch Then
    AForm.Bookmark = .Bookmark
    End If
    End With
    AForm.Painting = True

    FormRequery = True

    End Function

    with
    FormRequery Forms("frmcypNew").Form, ID

    Another solution before closing your popup:

    Forms("frmcypNew").Form.Requery
    Forms("frmcypNew").Form.Bookmark = Popup.Bookmark
    DoCmd.Close acForm, "PopupForm"

    mfG
    --> stefan <--
     
    Stefan Hoffmann, Jul 11, 2006
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bradley C. Hammerstrom

    Open and goto same ID on subform

    Bradley C. Hammerstrom, Sep 12, 2003, in forum: Microsoft Access Form Coding
    Replies:
    11
    Views:
    437
    Iryna Roy
    Sep 12, 2003
  2. Brian

    Move to Last and refresh

    Brian, Jul 7, 2004, in forum: Microsoft Access Form Coding
    Replies:
    3
    Views:
    126
    Brian
    Jul 28, 2004
  3. Guest

    Goto last record in a form

    Guest, Jan 24, 2005, in forum: Microsoft Access Form Coding
    Replies:
    5
    Views:
    194
    Ken Snell [MVP]
    Jan 26, 2005
  4. Guest

    How to goto last record in 2nd table?

    Guest, Jun 24, 2005, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    157
    Guest
    Jun 24, 2005
  5. Lloyd

    how to goto last record, add new record

    Lloyd, Sep 19, 2009, in forum: Microsoft Access Form Coding
    Replies:
    14
    Views:
    480
    Stuart McCall
    Sep 21, 2009
Loading...

Share This Page