Refreshing form's recordsource

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I have a form "A" that has as its recordsource
a simple query. Form "A" opens form "B" that
amongst other things might add records to the
recordsource that underlies Form "A". What
does form "A" have to issue in order that any
additions made to its recordsource by Form
"B" appear when Form "B" closes?

I tried Me.Requery following the DoCmd.OpenForm
of Form "B", but that had no effect. Also Me.Refresh.

Bill
 
Try using the entire reference to the form.
Forms![NameOfFormA] .requery

Replace the "NameOfFormA" with the actual name of your form.
 
Bill said:
I have a form "A" that has as its recordsource
a simple query. Form "A" opens form "B" that
amongst other things might add records to the
recordsource that underlies Form "A". What
does form "A" have to issue in order that any
additions made to its recordsource by Form
"B" appear when Form "B" closes?

I tried Me.Requery following the DoCmd.OpenForm
of Form "B", but that had no effect. Also Me.Refresh.

Unless you open Form B in dialog mode, thereby halting all code
execution in Form A until Form B is closed, a sequence such as

DoCmd.OpenForm "Form B"
Me.Requery

will cause Form A to be requeried before Form B has even finished
loading. You could get around this by opening Form B in dialog mode:

DoCmd.OpenForm "Form B", WindowMode:=acDialog
Me.Requery

Or you could use the Close event of *Form B* to requery Form A. Here's
an example:

'----- code for module of Form B -----
Private Sub Form_Close()

If CurrentProject.AllForms("Form A").IsLoaded Then
Forms("Form A").Requery
End If

End Sub
'----- end code -----
 
Dirk, I think the 2nd suggestion makes more sense, in that
Form "B" MAY NOT have done anything to change the
underlying recordsource of Form "A". Thus, the Requery
would only be done if it has.

Does Form "A" still have to open Form "A" using
acDialog? Intuitively, I wouldn't think so.

Bill
 
Bill said:
Dirk, I think the 2nd suggestion makes more sense, in that
Form "B" MAY NOT have done anything to change the
underlying recordsource of Form "A". Thus, the Requery
would only be done if it has.

Yes, that's one of the benefits of doing it that way. Or you could have
B requery A any time it makes a change that affects A (provided that A
is open).
Does Form "A" still have to open Form "A" using

Presumably you mean "open Form 'B'".
acDialog? Intuitively, I wouldn't think so.

And you'd be right.
 
That works great. I put the code to Requery Form "A" in the
one place where Form "B" has successfully performed
several SQL Inserts into the recordsource for Form "A".

Thanks a bunch!

Bill
 
Back
Top