473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to Cancel with option Yes No

on my form, I have a "Cancel" button which allows user to cancel updates and here is my code:
Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2.     Dim frm As Form
  3.     Set db = CurrentDb
  4.     Set frm = Forms!frmReview
  5.  
  6.     If Me.Dirty Then 'Check to see if record has been updated.
  7.         DoCmd.RunCommand acCmdUndo
  8.         DoCmd.Close acForm, "frmReview"
  9.     Else
  10.         DoCmd.Close acForm, "frmReview"
  11.     End If
  12. End sub
  13.  
the above code will close the form without save the form when user click on the 'cancel' button. What I would like to do is to add option Yes or No when user click on Cancel button. When user chooses Yes, form will be closed without saving the changes. When user chooses No, message box close and form stay openw with the changes. Here is my code, but it doesn't work properly

Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2.     Dim frm As Form
  3.     Set db = CurrentDb
  4.     Set frm = Forms!frmReview_V2
  5.     MsgBox "Cancel? Select Yes or No", vbYesNo, "Cancel Update!"
  6.     if vb=Yes then
  7.         DoCmd.RunCommand acCmdUndo
  8.         DoCmd.Close acForm, "frmReview"
  9.     elseif vb=No then
  10.         DoCmd.RunCommand acCmdUndo
  11.     End If
  12. end sub
  13.  
any help would be grealy appreciated.

bluemoon
Jul 6 '10 #1
8 7774
patjones
931 Expert 512MB
I think you're just a little confused about how the VB constants work. Try this...

Expand|Select|Wrap|Line Numbers
  1. Dim intCancel As Integer
  2.  
  3. intCancel = MsgBox ("Cancel? Select Yes or No", vbYesNo+vbQuestion, "Cancel Update!")
  4.  
  5. If intCancel = vbYes Then
  6.    DoCmd.RunCommand acCmdUndo
  7.    DoCmd.Close acForm, "frmReview"
  8. ElseIf  intCancel = vbNo Then
  9.    DoCmd.RunCommand acCmdUndo
  10. End If
  11.  
  12. End Sub
Jul 6 '10 #2
@zepphead80
Hi,
I tried the code, but it doesn't seem to work properly as well. it worked the first round, but second clicks do not perform the way I want.
In addition, the No part seems to be wrong because even though I select No, the updates that I've made to the records did not stay.

thanks!

bluemoon
Jul 6 '10 #3
@bluemoon9
I've tried this code, and it worked well with the No, but did not work for the Yes. I made some updates to the record, then click on Cancel, then choose yes, but the form still keep the updates even though I've assigned the form to be 'acSaveNo'

Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2.     Dim frm As Form
  3.     Set db = CurrentDb
  4.     Set frm = Forms!frmReview
  5.     Dim intCancel As Integer
  6.  
  7. intCancel = MsgBox("Cancel? Select Yes or No", vbYesNo + vbQuestion, "Cancel Update!")
  8.  
  9. If intCancel = vbYes Then
  10.    DoCmd.Close acForm, "frmReview", acSaveNo
  11. ElseIf intCancel = vbNo Then
  12. End If
  13. end sub
  14.  
bluemoon
Jul 6 '10 #4
patjones
931 Expert 512MB
You are sort of contradicting what you first posted when you started the thread. There you were using DoCmd.RunCommand acCmdUndo to throw out the changes before closing the form. Why aren't you using it now?

Pat
Jul 6 '10 #5
Thanks for the advice, i thought I could just use the command acSaveNo, then I do not need to use command acCmdUndo. I've placed the undo command back and it worked.
thanks!

bluemoon
Jul 7 '10 #6
nico5038
3,080 Expert 2GB
Hi bluemoon,

I wonder why you add a confirmation popup to the Cancel button as I regard them as annoying.
Normally I use an [OK] and a [Cancel] button and when my form has many fields I also add a [Reset] button to restore the initial field values.

Only a "risky" [Delete] button will justify additional confirmation in my view.

Nic;o)
Jul 7 '10 #7
@nico5038
I know, I would prefer the same way. That was how I programed the button in the first place; Once the user click on cancel, the form just close itself. However, my users have requested to add a code with the Y or N option because they said that sometimes they hit cancel button by mistake.

Bluemoon
Jul 7 '10 #8
nico5038
3,080 Expert 2GB
I know this "user problem" all too well Bluemoon :-)
Guess within half a year they'll get bored and ask you to remove it ..... <LOL>

Success with your application !

Nic;o)
Jul 7 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: eddie wang | last post by:
Excel open automatically without giving a dialog box option to Open/Save/Cancel using filesys.createTextFile. How to pop up the dialog box option to Open/Save/Cancel? Thanks.
2
by: Corrine | last post by:
Is there a way to cancel a change in an option group? The option group still changes to the option clicked on when clicking on the NO button with the following code in the BeforeUpdate event of the...
4
by: Deano | last post by:
Alot of my forms are bound. I would like to offer a Cancel option so that they can make as many changes as they like and still Cancel out without making any changes. I have one idea of how to...
14
by: clintonG | last post by:
This is an appeal for peer support sent to Microsoft as will be noted in closing. The Login control does not include a Cancel button. The only option is to convert the Login control to a...
3
by: Birky | last post by:
Hello, I’m hoping you can help me out with two issues I’m having with my code. I have an Access Report named Report_Project_Event_Log which I have calling a Form named “Custom_Code_lookup” which...
2
by: Swinky | last post by:
I have added a delete control to my form with code in the On Click property. The delete works well, but if I cancel the delete action, the record is still deleted. Here's the code: MsgBox...
1
by: carl2k2 | last post by:
Ok kind of new to this part, Here is my code I have set, If (CHKcat1 = 1) Or (CHKcatb = 1) Or (CHKcatc = 1) Or (CHKcorp = 1) Or (CHKexe = 1) Then response = MsgBox("Are you sure you want to...
16
by: parez | last post by:
I start a BackGroundWorker to populate a grid. It is started off in the ui layer The thread follows( cannot think of a better word) the path UI->Layer1->Layer2->Communication Layer and it...
2
beacon
by: beacon | last post by:
Hi everybody, I have a form that has a combo box that asks the user to select the program they work on. Once the user selects the program, a SQL statement populates the row source for 4 staff...
6
mageswar005
by: mageswar005 | last post by:
Hello Guys, I want to Avoid the Save option when i click the download link in php . I just want open and cancel option only, i dont want save option when i click the download link in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.