Problem with Controlled Closing of a Form when exiting throught the Window-Close-Button 
Author Message
 Problem with Controlled Closing of a Form when exiting throught the Window-Close-Button

Hi,
I have a Form where I need to control the data before the form closes. I put
in the Form_BeforeUpdate something like:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error Resume Next

    Dim strMsg As String
    Dim strTitle As String

    'Message
    If Me.NewRecord Then
        strMsg = "New Record?"
        strTitle = "Save?"
        Me.Angelegt_am = Now()
        Me.Angelegt_von = CurrentUser()
    Else
        strMsg = "Save changes?"
        strTitle = "Save changes?"
        Me.Aktualisiert_am = Now()
        Me.Aktualisiert_von = CurrentUser()
    End If

    If MsgBox(strMsg, vbYesNo + vbQuestion, strTitle) = vbYes Then
        'Check the Data.
        If Not Check_Form_Logic() Then
            Cancel = True
        End If
    Else
        'Undo
        Me.Undo
    End If

The Check_Form_Logic() - Funktion returns TRUE/FALSE in relation of the
correct data. When I exit the form throught the Window-Close-Button and the
Procedur Cancels the Update, Access runs into the Form_error-Procedure
raising the error 2169 -"You can't save this Record
know.....Access...blablabla".
How can I implement my own Custom Message-Box where to choose whether I want
to close the Form and discard all changes or keep it open and continue to
work. Maybe there is a simple API-Call to prevent the window from closing.

I do know about the examples in Access-Developer-Books, where you are
suppose to use the Form_Unload-Procedure, but until the Form reaches this
Procedure, all the changes the user made are lost!!!!!!!!!!

Thank you in advance,
Dirk Schlarb



Sat, 13 Nov 2004 01:39:51 GMT  
 Problem with Controlled Closing of a Form when exiting throught the Window-Close-Button
Take a look at the form UnLoad event. It fires when you click the form's close
button and is cancelable.

--

Sco

M.L. "Sco" Scofield, MCSD, MCT, MCP, MSS, Access MVP
Useful Metric Conversion #13 of 19: 3 1/3 tridents = 1 decadent
Miscellaneous Access and VB "stuff" at www.ScoBiz.com


Quote:
> Hi,
> I have a Form where I need to control the data before the form closes. I put
> in the Form_BeforeUpdate something like:

> Private Sub Form_BeforeUpdate(Cancel As Integer)
> On Error Resume Next

>     Dim strMsg As String
>     Dim strTitle As String

>     'Message
>     If Me.NewRecord Then
>         strMsg = "New Record?"
>         strTitle = "Save?"
>         Me.Angelegt_am = Now()
>         Me.Angelegt_von = CurrentUser()
>     Else
>         strMsg = "Save changes?"
>         strTitle = "Save changes?"
>         Me.Aktualisiert_am = Now()
>         Me.Aktualisiert_von = CurrentUser()
>     End If

>     If MsgBox(strMsg, vbYesNo + vbQuestion, strTitle) = vbYes Then
>         'Check the Data.
>         If Not Check_Form_Logic() Then
>             Cancel = True
>         End If
>     Else
>         'Undo
>         Me.Undo
>     End If

> The Check_Form_Logic() - Funktion returns TRUE/FALSE in relation of the
> correct data. When I exit the form throught the Window-Close-Button and the
> Procedur Cancels the Update, Access runs into the Form_error-Procedure
> raising the error 2169 -"You can't save this Record
> know.....Access...blablabla".
> How can I implement my own Custom Message-Box where to choose whether I want
> to close the Form and discard all changes or keep it open and continue to
> work. Maybe there is a simple API-Call to prevent the window from closing.

> I do know about the examples in Access-Developer-Books, where you are
> suppose to use the Form_Unload-Procedure, but until the Form reaches this
> Procedure, all the changes the user made are lost!!!!!!!!!!

> Thank you in advance,
> Dirk Schlarb



Sat, 13 Nov 2004 06:04:04 GMT  
 Problem with Controlled Closing of a Form when exiting throught the Window-Close-Button
Thank you for your reply.

I do know that I can use the form UnLoad event to cancel the form's closing.
My problem is that when you cancel the BeforeUpdate event, Access raises the
error=2169 and runs into the Form_error event where it, by default, lets you
decide whether to close the form and discard all the changes or keep the
form open and continue to work.

How can I customize my own MsgBox to do this?

If you cancel the BeforeUpdate event all the changes are lost until you
reach the UnLoad event!!!

Thanks,
Dirk Schlarb



Quote:
> Take a look at the form UnLoad event. It fires when you click the form's
close
> button and is cancelable.

> --

> Sco

> M.L. "Sco" Scofield, MCSD, MCT, MCP, MSS, Access MVP
> Useful Metric Conversion #13 of 19: 3 1/3 tridents = 1 decadent
> Miscellaneous Access and VB "stuff" at www.ScoBiz.com



> > Hi,
> > I have a Form where I need to control the data before the form closes. I
put
> > in the Form_BeforeUpdate something like:

> > Private Sub Form_BeforeUpdate(Cancel As Integer)
> > On Error Resume Next

> >     Dim strMsg As String
> >     Dim strTitle As String

> >     'Message
> >     If Me.NewRecord Then
> >         strMsg = "New Record?"
> >         strTitle = "Save?"
> >         Me.Angelegt_am = Now()
> >         Me.Angelegt_von = CurrentUser()
> >     Else
> >         strMsg = "Save changes?"
> >         strTitle = "Save changes?"
> >         Me.Aktualisiert_am = Now()
> >         Me.Aktualisiert_von = CurrentUser()
> >     End If

> >     If MsgBox(strMsg, vbYesNo + vbQuestion, strTitle) = vbYes Then
> >         'Check the Data.
> >         If Not Check_Form_Logic() Then
> >             Cancel = True
> >         End If
> >     Else
> >         'Undo
> >         Me.Undo
> >     End If

> > The Check_Form_Logic() - Funktion returns TRUE/FALSE in relation of the
> > correct data. When I exit the form throught the Window-Close-Button and
the
> > Procedur Cancels the Update, Access runs into the Form_error-Procedure
> > raising the error 2169 -"You can't save this Record
> > know.....Access...blablabla".
> > How can I implement my own Custom Message-Box where to choose whether I
want
> > to close the Form and discard all changes or keep it open and continue
to
> > work. Maybe there is a simple API-Call to prevent the window from
closing.

> > I do know about the examples in Access-Developer-Books, where you are
> > suppose to use the Form_Unload-Procedure, but until the Form reaches
this
> > Procedure, all the changes the user made are lost!!!!!!!!!!

> > Thank you in advance,
> > Dirk Schlarb



Sun, 14 Nov 2004 03:36:11 GMT  
 Problem with Controlled Closing of a Form when exiting throught the Window-Close-Button

I have been having some trouble with this exact same
problem, and am now getting somewhere with solving it. I
have done what sounds like a similar thing to you, I
prompt for saving in the Before_Update event, and if the
answer is vbCancel I cancel the event. I also set form
level variables here to tell me later on that I pressed
Cancel, and also to store all the current values of the
record (to avoid the changed data getting wiped). Then I
put a piece of code in the Form_Error event:

    If DataErr = 2169 Then
        Response = False
    End If

This cancels the Access generated error message.

In the On_Unload event I put code like this:

    If Not g_blnCloseCompany Then
        txtCompany = g_strCompany
        g_blnCloseCompany = True
        Cancel = True
    End If

This way, you can override the close icon on the form
keeping any changed data intact. This seems to work for
me, although I will have to test it some more to be sure.

If you need any help with my suggestions, feel free to
email me - also if you find anything wrong with it or
have any suggestions please let me know.

Andy

Quote:
>-----Original Message-----
>Thank you for your reply.

>I do know that I can use the form UnLoad event to cancel
the form's closing.
>My problem is that when you cancel the BeforeUpdate

event, Access raises the
Quote:
>error=2169 and runs into the Form_error event where it,

by default, lets you
Quote:
>decide whether to close the form and discard all the
changes or keep the
>form open and continue to work.

>How can I customize my own MsgBox to do this?

>If you cancel the BeforeUpdate event all the changes are
lost until you
>reach the UnLoad event!!!

>Thanks,
>Dirk Schlarb


Newsbeitrag

>> Take a look at the form UnLoad event. It fires when

you click the form's

- Show quoted text -

Quote:
>close
>> button and is cancelable.

>> --

>> Sco

>> M.L. "Sco" Scofield, MCSD, MCT, MCP, MSS, Access MVP
>> Useful Metric Conversion #13 of 19: 3 1/3 tridents = 1
decadent
>> Miscellaneous Access and VB "stuff" at www.ScoBiz.com



>> > Hi,
>> > I have a Form where I need to control the data

before the form closes. I

- Show quoted text -

Quote:
>put
>> > in the Form_BeforeUpdate something like:

>> > Private Sub Form_BeforeUpdate(Cancel As Integer)
>> > On Error Resume Next

>> >     Dim strMsg As String
>> >     Dim strTitle As String

>> >     'Message
>> >     If Me.NewRecord Then
>> >         strMsg = "New Record?"
>> >         strTitle = "Save?"
>> >         Me.Angelegt_am = Now()
>> >         Me.Angelegt_von = CurrentUser()
>> >     Else
>> >         strMsg = "Save changes?"
>> >         strTitle = "Save changes?"
>> >         Me.Aktualisiert_am = Now()
>> >         Me.Aktualisiert_von = CurrentUser()
>> >     End If

>> >     If MsgBox(strMsg, vbYesNo + vbQuestion,

strTitle) = vbYes Then
Quote:
>> >         'Check the Data.
>> >         If Not Check_Form_Logic() Then
>> >             Cancel = True
>> >         End If
>> >     Else
>> >         'Undo
>> >         Me.Undo
>> >     End If

>> > The Check_Form_Logic() - Funktion returns TRUE/FALSE
in relation of the
>> > correct data. When I exit the form throught the

Window-Close-Button and
Quote:
>the
>> > Procedur Cancels the Update, Access runs into the

Form_error-Procedure
Quote:
>> > raising the error 2169 -"You can't save this Record
>> > know.....Access...blablabla".
>> > How can I implement my own Custom Message-Box where
to choose whether I
>want
>> > to close the Form and discard all changes or keep it
open and continue
>to
>> > work. Maybe there is a simple API-Call to prevent
the window from
>closing.

>> > I do know about the examples in Access-Developer-

Books, where you are

- Show quoted text -

Quote:
>> > suppose to use the Form_Unload-Procedure, but until
the Form reaches
>this
>> > Procedure, all the changes the user made are
lost!!!!!!!!!!

>> > Thank you in advance,
>> > Dirk Schlarb

>.



Tue, 16 Nov 2004 20:54:55 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Closing Form control vs Button control for Exiting

2. Form Close Vs Close Window button problem

3. Exit Control and close form

4. Close All Outlook Windows Before Exiting Windows

5. Windows ME Not Closing because of Hidden Window (Outlook Express) that won't close

6. closing child window closes all windows

7. Problems when closing a form in an Exit-Event

8. Closing a form when other form is opening but reopening when all forms closed

9. Problem closing a form..DoCmd.Close and form_unload conflict

10. Close all Outlook Windows before exiting


 
Powered by phpBB® Forum Software © phpBB Group