Solved

BeforeUpdate event problem

Posted on 2014-03-19
7
453 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 35

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

860 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