473,395 Members | 1,745 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,395 software developers and data experts.

MsgBox on Checkbox Before and After Update Event Behaviour

kobamfo
14
Hi Guys,
I have a Check box named "crypt" on a continuous form and I would like to pop up a message box depending on the value of the check box, Like this: If the Box is initially checked on load of the form and the user unchecked it, the message should say "...Click yes to continue or No to cancel" such that the click of "yes" would accept the User's unchecking of "crypt" and No would simply undo the update attempt. so I have this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub crypt_AfterUpdate()
  2. Dim Msg, Style, Title, Ctxt, Response, MyString
  3.  
  4. If crypt.Value = 0 Then
  5. Msg = "Are You sure you have unlocked the PDF?" & _
  6. "Click Yes to continue or No to Cancel"
  7.  
  8. Style = vbYesNo + vbExclamation + vbDefaultButton2
  9. Title = "File Unlock Warning"
  10. Ctxt = 1000
  11.  
  12. Response = MsgBox(Msg, Style, Title, Ctxt)
  13.  
  14.     If Response = vbYes Then
  15.     MyString = "Yes"
  16.     Cancel = True
  17.  
  18. Else
  19. MyString = "No"
  20. DoCmd.RunCommand acCmdUndo
  21.     End If
  22. End If
  23. End Sub
  24.  
The Problem is the reverse does not work! That is if "crypt" is in an unchecked state and the User checked it, on Click of "No" the Undo does not work. That is the check does not clear on Undo, Why?
Any Help, please.

Warm Regards.
Jan 21 '13 #1

✓ answered by NeoPa

Kobamfo:
That is the check does not clear on Undo, Why?
Simply put, because you have already applied the change. Undo, in any of its forms, only works on changes that have not yet been applied. As such, it would make better sense to handle this in the _BeforeUpdate() event procedure. That even has a special parameter in order to allow you to cancel the update if you determine it should be. {ControlRef}.Undo will handle the undo most appropriately, as it is specifically targeted to the control.

7 4839
zmbd
5,501 Expert Mod 4TB
One would assume that this check box is in the details section of the form?
Is this control bound?
Jan 21 '13 #2
TheSmileyCoder
2,322 Expert Mod 2GB
You have to be careful with the Docmd.Runcommand accmdundo, as that is to some degree context sensitive. I.e. the action that happens is based on what else has occurred prior to the action being taken.


Instead of using the AfterUpdate I would suggest you use the beforeupdate. In this case note that the value of the crypt field is the value it is going to have. Ie. if it was true, and you click it then the code will believe it to be false until you cancel it.

Your code also seems quite confusing. You have mystring which is not used and ctxt which is not used, and your lack of indentation makes it harder to view the logic. If crypt.value<>0 then nothing happens cause you haven't specified anything for that.

A simplified example:
Expand|Select|Wrap|Line Numbers
  1. Private sub crypt_BeforeUpdate(Cancel as integer)
  2.  
  3.   If vbYes= Msgbox("Did you intend to change the status",vbYesNo) then
  4.     'Yes, don't do more
  5.   Else
  6.     'No so we cancel
  7.     Cancel=True
  8.     Me.Crypt.Undo
  9.   End If
  10. End Sub
Jan 21 '13 #3
NeoPa
32,556 Expert Mod 16PB
Kobamfo:
That is the check does not clear on Undo, Why?
Simply put, because you have already applied the change. Undo, in any of its forms, only works on changes that have not yet been applied. As such, it would make better sense to handle this in the _BeforeUpdate() event procedure. That even has a special parameter in order to allow you to cancel the update if you determine it should be. {ControlRef}.Undo will handle the undo most appropriately, as it is specifically targeted to the control.
Jan 21 '13 #4
DanicaDear
269 256MB
Thank you. This helped me too. :-)
Feb 8 '17 #5
NeoPa
32,556 Expert Mod 16PB
Hi Danica. Always nice to hear from you. Hope you and family are all doing well.

Nowadays, I would be clearer and say to use the Cancel parameter in the {Control}_BeforeUpdate event procedure for preference. {Control}.Undo is for macros or for code outside of the specific event procedure itself.
Feb 10 '17 #6
TheSmileyCoder
2,322 Expert Mod 2GB
I beg to differ a bit. If a user selects a bad entry in say a combobox, perhaps a status that is not valid, I usually prefer to force the value back to the original value (Otherwise the user is forced to either select the old value (which he might not remember) or do a manual undo(esc))
So usually my code might be:
Expand|Select|Wrap|Line Numbers
  1. Private Sub SomeControl_BeforeUpdate(Cancel as Integer)
  2. Msgbox "This status is not valid, while ...."
  3. Cancel=True
  4. SomeControl.Undo
  5. End Sub
Feb 11 '17 #7
NeoPa
32,556 Expert Mod 16PB
You're always welcome to differ Anders. However, in this case, I think you'll find that the .Undo is unnecessary as setting Cancel = True has the same effect anyway. It would probably act first as the Cancel value is only processed after the event procedure has completed, but I feel that the Cancel = True code is more appropriate from within an event procedure.

It makes more sense to use .Undo for objects which are not the object directly being handled.
Feb 15 '17 #8

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

Similar topics

1
by: Jason | last post by:
I have a main form with a sub form. All the fields in the subform are mandatory. I had some code on the main form Before Update Event to check if all the fields in the sub form have data. If not, I...
3
by: David | last post by:
Hi I use a calendar to update a field and the after update event no longer works, if i manually update it there is not a problem. How can I get this event to trigger Thanks in advance Dave
1
by: Paul Smith | last post by:
I have entered some code in the CheckBox CheckChanged event, but it does not seem to be function. I want to run some code when the check box is changed, and code run depending on it's checked or...
1
by: Tony | last post by:
Hi, In a form, when I modify some data and move to the next record, I want be able to trap an event and do a query to check on the change done to the table. Currently, I use the form After...
4
by: Mikep99 | last post by:
I am new to access and need some help with coding. I have a main form XYZ with 2 subforms. I have a checkbox on subform1 "frmExpediteS" that when checked i would like the Value in Feild "PO" of this...
5
by: c_shah | last post by:
using VB.net (2005) ASP.net 2.0 I have a repeater control with the item template, in the item template I have two checkboxes How to capture event When user checks the checkboxes? What event...
4
by: injanib via AccessMonster.com | last post by:
I have a combo box called "Recipient" who's row source is a table called "Main" with three columns. The three columns are "Name", "Floor", "Location". Following the combo box are two fields called...
1
by: QuickBooksDev | last post by:
VB.NET 2005 DataGridView Checkbox - Check Event need to know check status I would like to use the DataGridView Checkbox like a normal checkbox. When someone clicks on it I would expect that I...
5
by: Zeeshan7 | last post by:
After Update Event Procedure on a form is not working after upsizing database to SQL server. Anything to add in below code as it generate run time error 3622 "You must use the dbSeeChanges option...
2
by: rljsjones | last post by:
Hi, I have a checkbox (AllofNevada) that should enable/disable a checkboxlist (of counties in Nevada). The javascript code I have works. I placed the code: Protected Sub...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.