I have a family history database. I occasionally need to add a father or mother to a record "on the fly". I do not want to close the database, add a record, then open it again. Accordingly, I added a button btnQuickAdd which opens a small form (frmQuickAdd) to add in the father/mother's name, date of birth, and gender. The frmQuickAdd has a "Save" button which closes the frmQuickAdd and then requeries the main form using code DoCmd.Close acForm, "frmQuickAdd", acSaveYes Me.Requery However, using me.requery just results in error 2467 - the object is not open or does not exist. The main form clearly is still open. What am I doing wrong please?
0
votes
1 Answers
1
votes
As it is, you are trying the requery the frmQuickAdd
.
I presume your frmQuickAdd
is loaded through a button on the main form. If that's the case, then the .Requery
needs to happen on the next line where the form is loaded.
Private Sub btnQuickAdd_Click()
'open form
DoCmd.OpenForm "frmQuickAdd", acNormal, , , acFormPropertySettings, acDialog
'requery
Me.Requery
End Sub
Also, you can avoid the hard-coded form name when closing by using the form's Name
property:
DoCmd.Close acForm, Me.Name, acSaveYes
Edit
The above snippet will always requery the main form when the edit-form is loaded. If this behavior is not wanted, you can requery the main form when the save button is clicked using the form's name.
DoCmd.Close acForm, Me.Name, acSaveYes
Forms.MainForm.Requery
Note, MainForm
must be loaded or you'll get an error.
Me.
on closing form but absolute reference to main form:Forms("mainform").Requery
. – Parfait