Reputation: 215
I have an Access form that is supposed to close its predecessor -
If CurrentProject.AllForms("fmFileCheck").IsLoaded Then
DoCmd.Close acForm, "fmFileCheck", acSaveNo
Else
End If
The IF statement works fine (I have injected a message box to test) but the form simply doesn't close. No error message or anything, it just sits there and tants me, like a squirrel taunts a cat.
Edit:
The form opens on the "current" event of its predecessor and the code above executes on "current" - but if the code to open the second form is called via a button on the first then it works fine - so the issue I guess is somewhere in there?
Upvotes: 0
Views: 3393
Reputation: 3
I had a similar problem with a form (continuous form, showed Company Info, address, contact info etc) its stand alone, though opened from a button click from another form. The form was for viewing data only, no data entry; so I had set Data Enabled to False. The Form would not close by using a Button (click event drives docmd.close acform, me.name), regardless of how the form was opened (from another form or from the navigation bar on the left).
I opened it recently decided to switch Data Enabled False to True and Data Lock to True (from false). After completing that the button the form began working again. Don't know if switching those two settings had anything to do with it or not; but the only other thing I had done to the form was adjust the tab order (the Close button was at the bottom of the list and remained there).
Upvotes: 0
Reputation: 27634
You can't close a form while one of its event procedures is running.
Actually you should be getting a
Run-time error '2585': This action can't be carried out while processing a form or report event.
Do you have an On Error Resume Next
in your code? This can be dangerous.
My usual way to de-couple events is to use the Timer event.
In your second form, where the above code would run, do:
Me.TimerInterval = 1
and then (also in the second form)
Private Sub Form_Timer()
Me.TimerInterval = 0
If CurrentProject.AllForms("fmFileCheck").IsLoaded Then
DoCmd.Close acForm, "fmFileCheck", acSaveNo
End If
End Sub
Upvotes: 1
Reputation: 1
A possibility is that your form is actually named frmFileCheck and not fmFileCheck? Double check the spelling on the name of your form.
You can also debug the program to see if the condition is True and the command is being executed.
I would think that you don't need to nest the close command in an if loaded statement. Just execute the command and if it is loaded, it will close it. I am almost positive you will not get an error by closing a form that is not loaded.
Upvotes: 0