Close form query

jalldridge

Registered User.
Local time
Today, 18:56
Joined
May 3, 2005
Messages
60
Hi guys,

I have a form that the user uses to input data. If the user tries to close the form by clicking on the X then a warning message is displayed such as:

The field cannot contain a Null value because the required property for this field is set to true. Enter a value in the field.

What I want to happen is that when the user closes the form via the X, then no updates are undertaken (in effect a cancel operation).

How do I do this???

Thanks
 
Why don't you use the form's BeforeUpdate event to determine whether the user wants to save changes?


i.e. something like this

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If MsgBox("Save changes?", vbQuestion + vbYesNo, "Save?") = vbNo Then
        Me.Undo
        Cancel = True
    End If
End Sub
 
Thanks for feedback.

As I always need to do a cancel and not save anything I use the following code:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    Me.Undo
    Cancel = True
    
End Sub

However if I close the form by the X I am then presented with the following:

"You cant save this record at this time.

Eval Database may have encountered an error while trying to save a record. If you close this object now, the data changes you made will be lost. Do you want to close the database object anyway"

How can I just get the form to close (without saving) and the user not having any prompts?
 
On your form properties , Format set close button to no
Have an add record button (on its on click property validate all the fields)
User clicks this to add a record

Have a cancel record button ( the wizard will produce the code you nedd automatically)
The user clicks this to cancel a record

N.B.
If you dont disable the close button property and the user partly fills in the fildsa and then clicks on the X you may have a partila record stored
 
Hi Smart,

Yep I could add buttons, but if possible I would like the user to be able to cancelling the form by hitting the X. This would keep the look and feel of the app in line with the others they are used to using.

Anyway I can prevent / bypass the prompt from appearing?

Thanks
 
In the form properties , event, on close you can trap the error that the user gets when clicking on the x and then ignore it.
The user will then not see the errors
 
Hi Smart,

Ok nearly there I think :-)

One further complication.

If the user clicks the X and closes the form, the beforeUpdate event is called. If the user hits the next button in the navigation section (to enter data) then the beforeEvent button is again called.

How can I distinguish if the X button has been called so that I can use a me.undo in this instance? Obviously dont want to do a this when data needs to be added...

Ta
 

Users who are viewing this thread

Back
Top Bottom