How to refresh an open form?

A

Amit

Hi,

I have formA which includes a subform - sformB, to display
existing records for "Activity". I also have a button on
formA to open formC and add NEW Activity.

Is there a way to refresh formA (or rather sformB) after I
click on the button and add a new Acitivity in formC, such
that it displays the newly added Activity? Will refreshing
formA also refresh all the subforms included in it? formA
remains open while a new record is added to formC.

Thanks!

-Amit
 
D

Dirk Goldgar

Amit said:
Hi,

I have formA which includes a subform - sformB, to display
existing records for "Activity". I also have a button on
formA to open formC and add NEW Activity.

Is there a way to refresh formA (or rather sformB) after I
click on the button and add a new Acitivity in formC, such
that it displays the newly added Activity? Will refreshing
formA also refresh all the subforms included in it? formA
remains open while a new record is added to formC.

Thanks!

-Amit

You need to requery, not refresh, the subform. "Refresh" means "show
the most current field values for the records I currently have loaded",
while "requery" means "load this object's records all over again,
picking up any records that were added since the last time."

The statement to use, if executed from code behind formA, is

Me.sformB.Requery

If you open formC in dialog mode (DoCmd.OpenForm "formC",
WindowMode:=acDialog) then you can put the above statement immediately
after the DoCmd.OpenForm call.

If you don't open formC modally, then you'd better let the Close event
of formC requery the subform:

'----- (in formC) -----
Private Sub Form_Close()

If CurrentProject.AllForms("formA").IsLoaded Then
Forms!formA!sformB.Requery
End If

End If
 
A

Amit

Dirk,

Thank you (again)!! That worked.

-Amit

-----Original Message-----


You need to requery, not refresh, the subform. "Refresh" means "show
the most current field values for the records I currently have loaded",
while "requery" means "load this object's records all over again,
picking up any records that were added since the last time."

The statement to use, if executed from code behind formA, is

Me.sformB.Requery

If you open formC in dialog mode (DoCmd.OpenForm "formC",
WindowMode:=acDialog) then you can put the above statement immediately
after the DoCmd.OpenForm call.

If you don't open formC modally, then you'd better let the Close event
of formC requery the subform:

'----- (in formC) -----
Private Sub Form_Close()

If CurrentProject.AllForms("formA").IsLoaded Then
Forms!formA!sformB.Requery
End If

End If

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 

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