View Full Version : Check Close button pressed


John M
12-25-2001, 08:11 AM
Merry Christmas!!

For field validation I an using the before update event to trap for errors. On the form I have a close button which should rollback changes and close the form. I am finding that when I press this close button the before update event of the field is activated and because there is an error I am not allowed to close the form. The obvious workround would be to delete the field and press close again. Please advise.

R. Hicks
12-25-2001, 11:01 AM
Post the code you are using with your Close Button. Do you want to give a choice to fix the entry or undo all changes and close without saving the entry?

RDH

John M
12-25-2001, 05:22 PM
Dear R. Hicks,

Here is the code in the close button:
Private Sub btnClose_Click()
UndoMain Me, "tblBookInformation Temp"
DoCmd.Close

Here is the code in field with validation:
Private Sub Book_ID_BeforeUpdate(Cancel As Integer)
Dim sBook As Variant
Dim sCriteria As String

sCriteria = "[Book_ID] = '" & Me.Book_ID & "'" & " AND [BookType] = '" & Me.Combo67 & "'"
sBook = DLookup("[Book_ID]", "tblBookInformation", sCriteria)

If Not IsNull(sBook) Then
MsgBox "Book ID duplicate - update existing record"
Cancel = True
End If
End Sub

I want to Ask them are they sure and then if yes close the window without saving.

Thanks in advance

John M
12-26-2001, 10:24 AM
Can somebody help me out here please????

John M
12-30-2001, 11:53 AM
!!HELP Me. Has anyone encountered this problem before.

John.Woody
12-31-2001, 02:37 AM
Try looking at the help file for msgbox function, you can specify a YESNO msgbox. If yes then look at the help file for dirty, this may help canceling the record.

hth

John