• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

Quickie! How do cancel a shange to a field

This is one I should know !

In a form if the user changes the field tblCustomers.DiscountRate from 10% to 20%

The user will be prompted "Are you sure ? OKCancel " via a message box.

If the user clicks "Cancel" then how to I change the DiscountRate back to its initial value on the form.
Very simple - I am sure !??
0
Patrick O'Dea
Asked:
Patrick O'Dea
  • 6
  • 6
  • 5
2 Solutions
 
Dale FyeCommented:

Use the Undo method on that control, something like:

me.txt_DiscountRate.undo

0
 
Rey Obrero (Capricorn1)Commented:
ME.DiscountRate.UNDO
0
 
Dale FyeCommented:
Actually, you could use the BeforeUpdate event of the control, and if the user clicks 'Cancel' then you would just set Cancel = true.

Private Sub txt_DiscountRate_BeforeUpdate(Cancel as Integer)

    if msgbox("Are you sure", vbCritical + vbOkCancel, "Discount rate changed") = vbCancel then
        Cancel = True
    End If
end Sub

Or you could use the AfterUpdate event and use the Undo method mentioned above

Private Sub txt_DiscountRate_AfterUpdate

    if msgbox("Are you sure", vbCritical + vbOkCancel, "Discount rate changed") = vbCancel then
        me.txt_DiscountRate.Undo
    End If

End Sub    
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Patrick O'DeaAuthor Commented:
Thanks for the responses,
I know they are right but I cannot get it working just yet.
See my code attached.

NOTE: This is a different version to my original query!

If I click on cancel then the "No Action Taken" msgbox is shown (which is what I want).

However, the display of the region does NOT revert to it's original value on the form.(The region is a combo but this is presumably irrelevant)
If Region.OldValue <> Region.Value Then
    If MsgBox("WARNING: Changing the region Delete The Order Lines", vbOKCancel, "Update Or Cancel") = vbOK Then
    MsgBox "This message is for test only"
Else
    Me.Region.Undo
    MsgBox "No Action Taken"
End If
End If

Open in new window

0
 
Rey Obrero (Capricorn1)Commented:
where are you executing the codes ( what event?)
you must use the beforeupdate event of the control.
0
 
Rey Obrero (Capricorn1)Commented:
you must use the beforeupdate event of the control or of the form.
0
 
Patrick O'DeaAuthor Commented:
Thanks capricorn1,

I am actually using the beforeupdate event.  (!!)

I am obviously doing something wrong.
I will take a break and revisit this matter in a short while.
Sometimes a break works wonders !

Thanks again!
0
 
Dale FyeCommented:
Actually, you can use the AfterUpdate event of the control (not the form), if you use the Undo method.

But if you are going to use the BeforeUpdate event, you must set the Cancel property to True instead of using the Undo method.
0
 
Dale FyeCommented:
Try:

If Region.OldValue <> Region.Value Then
    If MsgBox("WARNING: Changing the region Delete The Order Lines", vbOKCancel, "Update Or Cancel") = vbOK Then
        MsgBox "This message is for test only"
    Else
        Cancel = True
        MsgBox "No Action Taken"
    End If
End If
0
 
Rey Obrero (Capricorn1)Commented:
21Dewsbury,
it is important to post the complete codes, to fully understand what you were trying to do and to make an assesment why the code is ot functioning as it should.
0
 
Patrick O'DeaAuthor Commented:
Hi again,
See attached.

Click form MainMenu.
Click "Process Sales Calls"
Click "Click Me" button on left of top line of datasheet.

You should now see a form with a customer called "Joe Bloggs".

Note the "Region" combo on the bottom left of the screen.
Change the value in the combo and you will be offered a msgbox.
Click Cancel and you will see "No Action Taken".

Question: Why does the "Region" NOT revert to it's original value.
Thanks in anticipation!
EEReport.accdb
0
 
Dale FyeCommented:
Sorry, corporate policy prevents me from downloading your application.  If you cut and paste all of the code associated with the BeforeUpdate event of the combo box, I might be able to provide additional assistance.  Did you try my previous suggestion (#35689506)?
0
 
Patrick O'DeaAuthor Commented:
Thanks fyed ,

I did try your earlier code but it did not work.

At this stage of the query I feel that the problem will be easiest resolved by a simple download of the database (which you unfortunately cannot do!).

Any other takers.
0
 
Rey Obrero (Capricorn1)Commented:
create a blank .mdb.
import all the relevant objects
upload the .mdb
0
 
Patrick O'DeaAuthor Commented:
WIll this suffice?

EE0405.mdb
0
 
Rey Obrero (Capricorn1)Commented:
try this codes


Private Sub Region_BeforeUpdate(Cancel As Integer)

If Region.OldValue <> Region.Value Then
    If MsgBox("WARNING: Changing the region Delete The Order Lines", vbOKCancel, "Update Or Cancel") = vbOK Then
    CurrentDb.Execute "update tblquotedetails set customerid=9999999 where CustomerID=" & Me.CustomerID
    MsgBox "Order Lines(if any) Have Been Deleted"
Else
    '  *********   HOW DO I RESTORE VALUE
    Me.Region.Undo   '<< ADD this line
    Cancel = True
    MsgBox "No Action Taken"
End If
End If

End Sub
0
 
Patrick O'DeaAuthor Commented:
Thanks ,
That's it!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now