How do i cancel an Event

  • Thread starter Thread starter David Ehrenreich
  • Start date Start date
D

David Ehrenreich

I have a on Click event that updates a subform in another
form. It works fine when both forms are open, but if the
form that gets updated is close an error appears.

here what I have so far.

Private Sub Form_AfterUpdate()
Forms![StudentLookup]![VisitsWindowSbfrm].Requery
End Sub

How do I stop the event if the form is closed so no error
appears?

Thank You
Any help would be great

David Ehrenreich
 
Try something along the lines of

If Allforms![StudentLookup].IsLoaded Then
Forms![StudentLookup]![VisitsWindowSbfrm].Requery
End If

Hope This Helps
Gerald Stanley MCSD
 
David said:
I have a on Click event that updates a subform in another
form. It works fine when both forms are open, but if the
form that gets updated is close an error appears.

here what I have so far.

Private Sub Form_AfterUpdate()
Forms![StudentLookup]![VisitsWindowSbfrm].Requery
End Sub

How do I stop the event if the form is closed so no error
appears?


You could explicitly check if the other form is loaded.

If CurrentDb.AllForms!StudentLookup.IsLoaded Then
Forms![StudentLookup]![VisitsWindowSbfrm].Requery

Another method would just ignore the error you're getting.

On Error Resume Next
Forms![StudentLookup]![VisitsWindowSbfrm].Requery

Probably a better way would be to use full error checking
and trap/ignore the this error, but deal with any other
error that might happen.

On Error GoTo ErrHandler
Forms![StudentLookup]![VisitsWindowSbfrm].Requery

ExitHere:
ExitSub

ErrHandler:
Select Case
Case 2450
Resume ExitHere
Case Else
MsgBox "Err.Number & " - " & Err.Description
Resume ExitHere
End Select
End Sub
 
Back
Top