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 -
Private Sub crypt_AfterUpdate()
-
Dim Msg, Style, Title, Ctxt, Response, MyString
-
-
If crypt.Value = 0 Then
-
Msg = "Are You sure you have unlocked the PDF?" & _
-
"Click Yes to continue or No to Cancel"
-
-
Style = vbYesNo + vbExclamation + vbDefaultButton2
-
Title = "File Unlock Warning"
-
Ctxt = 1000
-
-
Response = MsgBox(Msg, Style, Title, Ctxt)
-
-
If Response = vbYes Then
-
MyString = "Yes"
-
Cancel = True
-
-
Else
-
MyString = "No"
-
DoCmd.RunCommand acCmdUndo
-
End If
-
End If
-
End Sub
-
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.
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?
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: - Private sub crypt_BeforeUpdate(Cancel as integer)
-
-
If vbYes= Msgbox("Did you intend to change the status",vbYesNo) then
-
'Yes, don't do more
-
Else
-
'No so we cancel
-
Cancel=True
-
Me.Crypt.Undo
-
End If
-
End Sub
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.
Thank you. This helped me too. :-)
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.
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: - Private Sub SomeControl_BeforeUpdate(Cancel as Integer)
-
Msgbox "This status is not valid, while ...."
-
Cancel=True
-
SomeControl.Undo
-
End Sub
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |