MS Access Code

M

Melbourne

When I close a form I want to check if another form is open, if it is I want
to requery it otherwise I just want to close the form.

Does anyone know if there is code that I can use on the Close that will do
that.

Thanks
 
A

Allen Browne

Private Sub Form_UnLoad(Cancel As Integer)
If CurrentProject.AllForms("Form2").IsLoaded Then
Forms("Form2").Requery
End If
End Sub
 
M

Melbourne

Thanks Allen.

I have tried the code You supplied as below, Form name is "DailyPlan", I get
no errors but the form does not requery. Have I typed it wrong?

If CurrentProject.AllForms("DailyPlan").IsLoaded Then
 
A

Allen Browne

What does the error message say?
Which line gives the error?
Does it compile? (Compile on Debug menu)

What version of Access? This requires 2000 or later.

Is DailyPlan a form on its own, or a subform?

Alternative syntax:
Forms!DailyPlan.Requery

(The suggested syntax was to make it easy to use a string variable for the
form name.)
 
M

Melbourne

Thanks Allen,

There was no error message, I use Access 2007 and your last selection has
worked.

Thank you very much for your help.
 
Top