requery then close form

  • Thread starter Thread starter Angi
  • Start date Start date
A

Angi

I have a Contact form that opens with the main form behind it after a
cmdbtn is clicked. When the last field loses focus, I want the form to
requery the main form and close the Contact form. It requeries the
main form but then I get an error that the form can't close. What do I
need to do to close this form programatically?? TIA!

Run-time error '2585':
This process can't be carried out while processing a form or report
event.

Then highlights this line:
DoCmd.Close acForm, "contactmainform"
 
There's no obvious reason why the form fails to close.

One thing maybe worth trying would be to set the focus onto the main form...
forms![YourMainForm].setfocus
....before your close command.

If that doesn't work, or give you any other clues... could you provide a bit
more code just to show the context in which the close command is being run.
 
Rob,
I tried what you said and i'm still getting the same error. I thought
it might be the BeforeUpdate but that should only be there to check
whether or not the record is saved. I took the code out of the Close
event, but that didn't make a difference. Thx for your help! Here's
the code for the form:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!FirstName) And IsNull(Me!LastName) Then
Me.Undo
End If
End Sub

Private Sub Form_Close()
Forms!companymain.Requery
End Sub

Private Sub Form_Open(Cancel As Integer)
If (Not IsNull(Me.OpenArgs)) Then
Me!CoID.DefaultValue = Me.OpenArgs
End If
End Sub
Private Sub HFax_LostFocus()
Forms!companymain.Requery
Forms![companymain].SetFocus
DoCmd.Close acForm, "contactmainform"
End Sub

Private Sub HomeOffice_LostFocus()
If Not IsNull(LastName) Then
If HomeOffice = True Then
GoToPage 2
Else
Me!Salutation.SetFocus
End If
Else
Me!Salutation.SetFocus
End If
End Sub
 
Hmmm. I don't think you can close in the LostFocus event as the form is
still in the middle of processing. (..and similar for the control's exit
event). A bit of a kludge but you should be able to set...

me.timerinterval=1 in the LostFocus event

and then move the close command to the form's timer event.
 
Back
Top