Form Close Vs Close Window button problem 
Author Message
 Form Close Vs Close Window button problem

I have a form that is used both for data maintenance and addition. I use
code behind a button to establish a blank record:
     DoCmd.GoToRecord , ,acNewRec

The user inserts the needed data and uses an Access built button to do a
save. Since the user may decide to close and not save the data there is a
close button which just does a DoCmd.Close forcing everything through the
form unload and form close. In form unload; I test for this case:

Private Sub Form_Unload(Cancel As Integer)
    Dim strMsg      As String
    Dim intStyle    As Integer
    Dim strTitle    As String
    Dim intResponse As Integer
    Dim a As Long
    If IsNull(Me.SerialNumber) Or Me.SerialNumber = 0 Then
        strMsg = "Are you sure you want to delete this new document?"
        intStyle = vbYesNo + vbInformation + vbDefaultButton2
        strTitle = "Close Action"
        intResponse = Msgbox(strMsg, intStyle, strTitle)
        If intResponse = vbYes Then
            DoCmd.RunCommand acCmdUndo
       End If
    End If
End Sub

This part works fine. The problem is when they use the Close Window
button.(X)
This brings me to the other half of the problem. The user requires that I
maximize the form. Even through I have turned off the Min Max and control
Box buttons. As soon as I do a  DoCmd.Maximize they appear. I have found no
way to turn them off. Because of this I need both the Close window button
and my close button to perform the same way. Popup is not an option since
this will remove my user-defined menu.

When I use the close window button I get the message asking if I want to
delete the document from the form unload subroutine just as in the first
case. Then the form fields are cleared at which time it tries to write the
record, which then bounces on the validation rules requiring data.  Why does
close window appears to try and commit the data record prior to running the
form unload I don't know.

It seems that the record when we exit from close window is already committed
before it runs the form unload.

I would appreciate any comments on this problem. I need to get rid of the
close window button or at least find a way to process/trap it for
processing.

TomB



Wed, 31 Dec 2003 23:51:23 GMT  
 Form Close Vs Close Window button problem
Tom,

Unfortunately, you've encountered one of the nastier "stumbling blocks" in
Access.  For details, see the recent thread in this newsgroup entitled
"BeforeUpdate - How do I supress this message?" that was started on
11-Jul-2001.  Even getting rid of the title bar close button will not help
you avoid the problem since there are other ways to trigger closing of the
form, such as keyboard shortcuts (which you can't trap effectively since
anyone might be using software to override default windows keyboard
shortcuts), closing Access, or shutting down Windows entirely.

Nicole


Quote:
> I have a form that is used both for data maintenance and addition. I use
> code behind a button to establish a blank record:
>      DoCmd.GoToRecord , ,acNewRec

> The user inserts the needed data and uses an Access built button to do a
> save. Since the user may decide to close and not save the data there is a
> close button which just does a DoCmd.Close forcing everything through the
> form unload and form close. In form unload; I test for this case:

> Private Sub Form_Unload(Cancel As Integer)
>     Dim strMsg      As String
>     Dim intStyle    As Integer
>     Dim strTitle    As String
>     Dim intResponse As Integer
>     Dim a As Long
>     If IsNull(Me.SerialNumber) Or Me.SerialNumber = 0 Then
>         strMsg = "Are you sure you want to delete this new document?"
>         intStyle = vbYesNo + vbInformation + vbDefaultButton2
>         strTitle = "Close Action"
>         intResponse = Msgbox(strMsg, intStyle, strTitle)
>         If intResponse = vbYes Then
>             DoCmd.RunCommand acCmdUndo
>        End If
>     End If
> End Sub

> This part works fine. The problem is when they use the Close Window
> button.(X)
> This brings me to the other half of the problem. The user requires that I
> maximize the form. Even through I have turned off the Min Max and control
> Box buttons. As soon as I do a  DoCmd.Maximize they appear. I have found
no
> way to turn them off. Because of this I need both the Close window button
> and my close button to perform the same way. Popup is not an option since
> this will remove my user-defined menu.

> When I use the close window button I get the message asking if I want to
> delete the document from the form unload subroutine just as in the first
> case. Then the form fields are cleared at which time it tries to write the
> record, which then bounces on the validation rules requiring data.  Why
does
> close window appears to try and commit the data record prior to running
the
> form unload I don't know.

> It seems that the record when we exit from close window is already
committed
> before it runs the form unload.

> I would appreciate any comments on this problem. I need to get rid of the
> close window button or at least find a way to process/trap it for
> processing.

> TomB



Thu, 01 Jan 2004 00:26:04 GMT  
 Form Close Vs Close Window button problem
Hi,
    This is one of the mayor pain in the necks i have to deal with also.
People don't care if you put a quit button the size of the screen, they will
close the program however they want, even sutting down windows if tey want
to, not way to keep them form doing it (without a lot of code, and even then
they can just pull the plug out of hte wall).
The way I deal with it, is rather than an on close or before save, etc. I
have all of the data write to a temp table, and i run all of the rutines on
my save button, close or quit.
If they close the form by any other way or mean, the data stays on the temp
table, if they did any changes and didn't comit they wouldn't be updated,
etc.
But the catch is that the next time they open the database, on the main form
i have code that checks the temp table, if it is there, i send them straight
there so that they can continue working on the last item. I though they
would hate this, but they actually love it. I took out a lot of the code I
use to have that prevented them from closing the form, and now everything
works fine. I actually use the same metode on all my projects since, and
even went back to the old ones and modify them to work like this.

hope it helps,

Rodrigo.

Quote:
> I have a form that is used both for data maintenance and addition. I use
> code behind a button to establish a blank record:
>      DoCmd.GoToRecord , ,acNewRec

> The user inserts the needed data and uses an Access built button to do a
> save. Since the user may decide to close and not save the data there is a
> close button which just does a DoCmd.Close forcing everything through the
> form unload and form close. In form unload; I test for this case:

> Private Sub Form_Unload(Cancel As Integer)
>     Dim strMsg      As String
>     Dim intStyle    As Integer
>     Dim strTitle    As String
>     Dim intResponse As Integer
>     Dim a As Long
>     If IsNull(Me.SerialNumber) Or Me.SerialNumber = 0 Then
>         strMsg = "Are you sure you want to delete this new document?"
>         intStyle = vbYesNo + vbInformation + vbDefaultButton2
>         strTitle = "Close Action"
>         intResponse = Msgbox(strMsg, intStyle, strTitle)
>         If intResponse = vbYes Then
>             DoCmd.RunCommand acCmdUndo
>        End If
>     End If
> End Sub

> This part works fine. The problem is when they use the Close Window
> button.(X)
> This brings me to the other half of the problem. The user requires that I
> maximize the form. Even through I have turned off the Min Max and control
> Box buttons. As soon as I do a  DoCmd.Maximize they appear. I have found
no
> way to turn them off. Because of this I need both the Close window button
> and my close button to perform the same way. Popup is not an option since
> this will remove my user-defined menu.

> When I use the close window button I get the message asking if I want to
> delete the document from the form unload subroutine just as in the first
> case. Then the form fields are cleared at which time it tries to write the
> record, which then bounces on the validation rules requiring data.  Why
does
> close window appears to try and commit the data record prior to running
the
> form unload I don't know.

> It seems that the record when we exit from close window is already
committed
> before it runs the form unload.

> I would appreciate any comments on this problem. I need to get rid of the
> close window button or at least find a way to process/trap it for
> processing.

> TomB



Thu, 01 Jan 2004 04:03:46 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with Controlled Closing of a Form when exiting throught the Window-Close-Button

2. Disable Access Close Button not Form Close Button?

3. User Form close buttons and timer close

4. Cancel/close form command button causes app to close

5. Close command button allows form to be closed when required fields are left blank

6. Close button, closes form to the wrong place

7. Cancel/close form command button causes app to close

8. Prevent user from closing form using caption close button

9. Problem with closing Excel with the close button

10. Closing Form control vs Button control for Exiting


 
Powered by phpBB® Forum Software © phpBB Group