Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BeforeUpdate event problem

Posted on 2014-03-19
7
Medium Priority
?
460 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 52

Accepted Solution

by:
Gustav Brock earned 2000 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 39

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 52

Expert Comment

by:Gustav Brock
ID: 39940020
You are welcome!

/gustav
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

618 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