Solved

BeforeUpdate event problem

Posted on 2014-03-19
7
445 Views
Last Modified: 2014-03-19
Access 2005/sql server 2005: I retrieve data from the sql server and display/edit it in unbound forms. I've always had the problem that if I use the BeforeUpdate event handler to validate some input, the user has to press the escape key in order to undo his changes.

I've tried each of the following just before the Cancel=True statement:

Sendkeys "{Escape}"

Me.Undo

Me![ComboBox].undo

and even this:

KeySend "{Escape}"

Public Sub KeySend(Keystrokes As String)
    On Error Resume Next
    Dim MyShell As Object
    Set MyShell = CreateObject("Wscript.Shell")
   
    MyShell.SendKeys Keystrokes
    Set MyShell = Nothing
   
End Sub

I think it's because i'm using unbound forms. How can I simulate an escape key press in this situation?

Ian
0
Comment
Question by:TownTalk
7 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39939395
Store the value in a variable at the OnEnter event.
If Cancel = True at the BeforeUpdate event, set the value of the control to the value of the stored variable.

/gustav
0
 

Author Comment

by:TownTalk
ID: 39939439
Hmmm.... yes well that looks like it will work. However.....

 I was using the above as an example. Actually this is a very large application with many dozens of unbound data entry forms. It would be quite an undertaking to write that functionality into every BeforeUpdate event handler. There will be hundreds of them.

I was hoping there is a way to make Access do this itself.
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39939599
Access does do it all by itself.  It is called BOUND forms.  When you use unbound forms, it is up to you to do it all by yourself.  That is the decision you made when you went with unbound forms.  Access gives you no help at all when you use unbound forms, nor should it.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:TownTalk
ID: 39939615
I accept that the .undo method shouldn't work, but I would have thought that I should be able to simulate pressing the escape key. If I manually press the Escape Key, I get the behavior that I want.
0
 
LVL 84
ID: 39939951
The only way I know of is to use the method suggested by Gustav, or use the SendKeys method (which is unreliable, at best). I'm not sure what pressing the Esc key does "under the covers" in Access, so it's impossible to say why one method works where another does not.
0
 

Author Comment

by:TownTalk
ID: 39940008
Thanks Scott. Neither Sendkeys nor my Keysend routine ever work in a BeforeUpdate scenario. So I have written a global routine which I can call from within any BeforeUpdate event. Actually it works very well. So thanks (and the points) go to Gustav.

Thanks everyone for your input.

Ian
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39940020
You are welcome!

/gustav
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now