Refresh & Goto Last

G

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
 
G

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
 
S

Stefan Hoffmann

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 <--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top