VBA code to silence an error on close?

scooteman

Registered User.
Local time
Today, 16:40
Joined
Nov 30, 2009
Messages
57
I have a Event Details dialog form to add new events. The form can be opened up from two different forms, the main Current Events list form and the Calendar view. I have the following code in the On Close event that syncs the Calendar with the new record.

Private Sub Form_Close()
'Explicitly Set Focus to the Calendar Form
Forms![frmCalendar].SetFocus

'Activate the Shortcut Key for the Sync Command Button
SendKeys "%S", True
End Sub

Everything works fine but if I open the Events dialog form from the Current Envents form and the calendar is closed, I get the nagging error message on close that it cannot find the form "frmCalendar". I tried setting warning to off but that doesn't work for these kind of error messages.

For now I have duplicated the dialog form and have each opening from the oppropriate form which is a simple fix. However, I have too many forms now and I would like to use just one. I also have a couple of forms that requery another form on close and I see the same error message on those if the target form is not open.

Thanks
 
You need to use the IsLoaded() function to check to see which form is open and issue the relevant code.

Code:
If IsLoaded("Form1") Then
   Do This
Else
   Do That
End If

David
 
That did it! thanks so much!!!
 

Users who are viewing this thread

Back
Top Bottom