Problem with closing a form

R

Rob

Hi all,

I have some code in the Forms Before_Update event. This code has always
worked when I use it before moving rows, but it does not work as
anticipated when I try to close a form (from the X in the ControlBox). When
I close a 'Dirty' form and select No, I am presented with the "Cant save
record at this time error". Any help would be appreciated,

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Select Case MsgBox(strSave, vbQuestion + vbYesNoCancel, "Save Task?")
Case vbNo
Me.Undo
Cancel = True
Case vbCancel
Cancel = True
End Select
End If

End Sub

Cheers
Rob
 
R

rm

I certain that I do not have the exact answer - but I have just faced
a similar issue.

I tried to use cancel only and then found that I had to use undo on
the control also.

Did you try Form.undo?
 
R

Rob

oh

Cancel = True
Me.Undo

per the MS Access help file.

Hi rm, thanks for the responses, however I am still having problems. I
changed my code to the snippet below, but no luck. I have also tried
wrapping this up in another sub routine, but it did not work either. I
will continue to work toward a solution and will post if I work anything
out. Most posts I have read say, however, that any validation should be
conducted in the Before_Update event!

Cheers
Rob

Private Sub Form_BeforeUpdate(Cancel As Integer)

If bSavePressed = False Then
If Me.Dirty Then
Select Case MsgBox(strSave, vbQuestion + vbYesNoCancel, "Save")
Case vbNo
Cancel = True
Me.Undo
Case vbCancel
Cancel = True
bOkToClose = False
End Select
End If
End If

End Sub
 
R

Rob

Hi all,

I have some code in the Forms Before_Update event. This code has always
worked when I use it before moving rows, but it does not work as
anticipated when I try to close a form (from the X in the ControlBox). When
I close a 'Dirty' form and select No, I am presented with the "Cant save
record at this time error". Any help would be appreciated,

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Select Case MsgBox(strSave, vbQuestion + vbYesNoCancel, "Save Task?")
Case vbNo
Me.Undo
Cancel = True
Case vbCancel
Cancel = True
End Select
End If

End Sub

Cheers
Rob

Hi all,

I found a solution to my problem at this site:

http://bytes.com/forum/thread647206.html

I still find it strange that I have to catch an error and then ignore it.
Like the OP in this topic, I have also written a routine that stores the
current field data and then restores it if the user selects cancel.

I am still to find out exactly why the Cancel = True setting does not work
in this case (maybe something to do with the underlying recordset?),
although I have a workaround so I will track it down later.

Cheers
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top