Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancelling data entry on exit.

Status
Not open for further replies.

bhoran

MIS
Nov 10, 2003
272
US
I have the following code to exit without saving and entry on a data entry form:

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click
Dim Msg, Response, Style, Title As String

Style = vbYesNo + vbWarning + vbDefaultButton2
Title = "Do you wish to exit"

Msg = "Exiting now will discard changes on the current record. If you wish to save changes click on No then click on the Save. If you wish to exit and disregard changes click on Yes. "

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
'Me.SubBrand.Undo (I tried adding this but had no effect)
Cancel = True
DoCmd.Close
End If

Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Command10_Click

End Sub

It works fine where the user has not entered data into a field that is required by the table validation but its does not work where the user has enetered everything but then decides they don't want to submitt the record - as I use combo boxes this may happen where they are not sure about a choice but once the combo box is open they are forced to make a choice.

My form is a dataentry form with each control bound to the underlying table.

I want to be able to cancel the entry without the record updating in the table? I have tried adding an undo in one of the fields that is required by the table validation but that did not work.

Cheers
 
Oops don't worry I have it sorted.

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click
Dim Msg, Response, Style, Title As String

Style = vbYesNo + vbWarning + vbDefaultButton2
Title = "Do you wish to exit"

Msg = "Exiting now will discard changes on the current record. If you wish to save changes click on No then click on the Save. If you wish to exit and disregard changes click on Yes. "

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
Me.Undo
DoCmd.Close
End If

Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Command10_Click

End Sub

works fine.

However, if anyone has another way please let me know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top