[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

BeforeUpdate event problem

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

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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

873 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