Solved

BeforeUpdate event problem

Posted on 2014-03-19
7
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 50

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 37

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
Industry Leaders: 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!

 

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 85
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 50

Expert Comment

by:Gustav Brock
ID: 39940020
You are welcome!

/gustav
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

688 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