Problem with form_Close() trigger

  • Thread starter Thread starter ccool
  • Start date Start date
C

ccool

Guest
When the close button on the top right of the form is pressed I want the following code to be run:

Private Sub Form_Close()

Dim preview As Boolean
Dim checkForOldBooks
Dim count As Integer

preview = False

count = DCount("*", "tblOldItems")

If count > 0 Then
Call saveAndOutput_Reports("rOldBooks", "oldBooks", preview)
Call saveAndOutput_Reports("rBarCodeList", "BarcodesScanned", preview)
Else
Call saveAndOutput_Reports("rBarCodeList", "BarcodesScanned", preview)
End If

DoCmd.Close

End Sub

I put this code in the Form_Close trigger because I want it to execute everytime the form is closed. The problem I'm having is when I run the form and press the close button the code does not seem to execute. However if I put a breakpoint in the trigger, run the form and press the close button, the program does go into the trigger and the code executes as it should when I step through it.

To troubleshoot I also created a button and added the above code, when the form is run and the button is pressed the code executes as it should it just does'nt work in the close_form trigger.

Does anyone know why this may be happening.
 
A possibility is that your reports rowsource refers to a control on the form which is in the process of closing or perhaps there is some other reference to a control on the closing form in the saveAndOutput_Reports subroutine. If this is the case then the report may not run because it cannot access the forms controls as it is closing.
I don't think you need the docmd.close statement because the form will be closing anyway if you are already in the form_close subroutine and that may be giving you an error.
 

Users who are viewing this thread

Back
Top Bottom