Cancel question

Geordie2008

Registered User.
Local time
Today, 23:25
Joined
Mar 25, 2008
Messages
177
Hi all,

I have a form which if the user selects "Add new" takes them to a data entry form which will populate an underlying table.

I wanted a "Cancel" button, so that if the user selected "add new" and changed their mind they could cancel without populating a blank row of data into the underlying table.

I guess I want to hit an "escape" button before the null values are passed to the underlying bound data table.

Thank you.
 
Put something like this as the first line in the code:

If MsgBox("Add Record?", vbYesNo + vbQuestion, "Add Record...") = vbNo Then Exit Sub
 
Mmmm... Is there any way to have a seperate Button for Cancel?

I cant think how I would be able to incorporate this logic.

I have predefined validation fields so if the user cant populate those then I want them to be able to exit? Otherwise I want them to be able to save the record as usual.

Thanks
 
You can replace vbYesNo with vbOKCancel but I don't think you can do a yes with a cancel - ?
 
Thanks Ken,

For some unknown reason the following seems to be working.... I had this code originally so a user could cancel any changes they had made within the form and exit. However it seems to cancel adding a new record also.....

Im still not 100% certain its bullet prof so Im testing and re-testing.... so far so good however!

Have a great weekend!
Mandy


Code:
Private Sub Cancel_Click()
On Error GoTo Err_Cancel_Click
If Me.Dirty Then
  Me.Undo
End If
DoCmd.Close acForm, "frmStaffDetails_ComboBox"
Exit_Cancel_Click:
  Exit Sub
Err_Cancel_Click:
  MsgBox Err.Description
  Resume Exit_Cancel_Click
 
End Sub
 
Ah... You wanted to back out after you got into the form. In that case your code makes perfect sense.
 
great stuff.... That makes me much more confident..... I think I hear the pub calling.....!

Have a good one!
Mandy
 

Users who are viewing this thread

Back
Top Bottom