473,804 Members | 3,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to program Escape key function in VBA?

Is there a way to programmaticall y emulate pressing the Escape key with VBA?
(Access 2003)

What I'm trying to do is clear a field in a form (which otherwise requires
the user to press Escape) after trapping a particular error. For example,
if the user enters a value in a form field that meets certain criteria, I
want to trap this as an error and clear the field with code (same thing as
pressing the Escape key). What code should I use to emulate pressing the
Escape key?

Thanks!
Nov 12 '05 #1
5 55168
On Wed, 31 Dec 2003 15:53:43 GMT, "deko" <dj****@hotmail .com> wrote:
Is there a way to programmaticall y emulate pressing the Escape key with VBA?
(Access 2003)

What I'm trying to do is clear a field in a form (which otherwise requires
the user to press Escape) after trapping a particular error. For example,
if the user enters a value in a form field that meets certain criteria, I
want to trap this as an error and clear the field with code (same thing as
pressing the Escape key). What code should I use to emulate pressing the
Escape key?

Thanks!

Use the Undo method in the Before Update event of the control.

If Me.txtBox = "foo" Then
Me.txtBox.Undo
Cancel = True
End If

- Jim
Nov 12 '05 #2
Thanks for the reply.

I'll give it a shot. I'm wondering if Undo is better than SendKeys:

SendKeys "{esc}", True

is there a difference?

Thanks again and happy new year!

"Jim Allensworth" <Ji****@NOTdata centricsolution s.com> wrote in message
news:3f******** ******@netnews. comcast.net...
On Wed, 31 Dec 2003 15:53:43 GMT, "deko" <dj****@hotmail .com> wrote:
Is there a way to programmaticall y emulate pressing the Escape key with VBA?(Access 2003)

What I'm trying to do is clear a field in a form (which otherwise requiresthe user to press Escape) after trapping a particular error. For example,if the user enters a value in a form field that meets certain criteria, I
want to trap this as an error and clear the field with code (same thing aspressing the Escape key). What code should I use to emulate pressing the
Escape key?

Thanks!

Use the Undo method in the Before Update event of the control.

If Me.txtBox = "foo" Then
Me.txtBox.Undo
Cancel = True
End If

- Jim

Nov 12 '05 #3
On Wed, 31 Dec 2003 17:30:28 GMT, "deko" <dj****@hotmail .com> wrote:
Thanks for the reply.

I'll give it a shot. I'm wondering if Undo is better than SendKeys:

SendKeys "{esc}", True

is there a difference?
There is a huge difference. You are best to avoid SendKeys. It should
only be used in *very* limited circumstances.

Do a google newgroups search on the subject for more information.
Thanks again and happy new year!


Happy new year to you as well.

- Jim

Nov 12 '05 #4
> Do a google newgroups search on the subject for more information.

I did come across some warnings about SendKeys and possible bugs in older
versions of Access.
There is a huge difference. You are best to avoid SendKeys. It should
only be used in *very* limited circumstances.


I'm all for sticking to best practices...

See below for how I'm using the Undo event - but I'm confused about a few
things. any enlightenment is appreciated...

what does "Cancel = True" do? - I tried this but it would not compile. -
just Me.Undo seems to be working okay...
what does "DoCmd CancelEvent" do?
how do I use the "On Undo" field in a form's property sheet?
Private Sub Whatever ()
[code omitted...]
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3022
Me.Undo
Resume Exit_Here
Case 94
Resume Next
Case Else
modHandler.LogE rr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub
Nov 12 '05 #5
The Undo method applies to a control object or a form object. It reset
the object.

When validating data, as you are doing, you can use it in the controls
Before Update event. The Before Update event has a Cancel argument
that when set to True will cancel the update and keep the focus on the
control.

To put what I posted earlier in this context it would be something
like...

Private Sub txtBox_BeforeUp date(Cancel As Integer)
If Me.txtBox = "foo" Then
MsgBox "No Foos allowed."
Me.txtBox.Undo
Cancel = True
End If
End Sub

For use in a form you might use Me.Undo in the Form's Before Update
event to reset the entire form.

- Jim

On Wed, 31 Dec 2003 21:53:15 GMT, "deko" <dj****@hotmail .com> wrote:
Do a google newgroups search on the subject for more information.


I did come across some warnings about SendKeys and possible bugs in older
versions of Access.
There is a huge difference. You are best to avoid SendKeys. It should
only be used in *very* limited circumstances.


I'm all for sticking to best practices...

See below for how I'm using the Undo event - but I'm confused about a few
things. any enlightenment is appreciated...

what does "Cancel = True" do? - I tried this but it would not compile. -
just Me.Undo seems to be working okay...
what does "DoCmd CancelEvent" do?
how do I use the "On Undo" field in a form's property sheet?
Private Sub Whatever ()
[code omitted...]
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3022
Me.Undo
Resume Exit_Here
Case 94
Resume Next
Case Else
modHandler.LogE rr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub


Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
9575
by: Richard Trahan | last post by:
I need a javascript function to hex-encode a plus sign so I can pass the plus sign as an argument in a GET request. escape() and encodeURI() don't do it (and probably shouldn't, because '+' is a valid character in a URI). I could write a regexp, but the environment I'm in won't allow replace(). I could write something cumbersome using indexOf, but if there's something easier, like a builtin function that encodes every character in the...
2
14481
by: Pavils Jurjans | last post by:
Hello, I am looking fow C# equivalent of JavaScripts escape() and unescape() functions. I need to use C# function at the server side and then be able to use the opposite at the client side. JavaScripts escape() function converts all non-alphanumerical chars to %xx, and all unicode chars to %uxxxx (where xxxx is unicode charcode). I'd like to have C# function that get this escaped string back to normal at the server side. Perhaps there...
2
5666
by: genc_ ymeri at hotmail dot com | last post by:
Hi , Does .Net have any method/function that escape charcters while writing a XML file ???? Thank you in advance.
10
8360
by: Danny | last post by:
In the classic asp, I can use escape built-in function (server side function) like this: <script language=javascript> var myContent = unescape(<%=escape(strContent)%>) </script> How do I do that in asp.net? Seems like escape server side function is no longer provided in asp.net, or am I missing something here?
1
3503
by: chuck | last post by:
Hi, I have a php function creating links from a products mysql database. some of the descriptions have characters that I need to escape but whatever i do, javascript doesn't like them. for example a product description might be 30' black ribbon I have tried backslash escapes and a php function, htmlspecialchars http://us3.php.net/htmlspecialchars
131
9297
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if you pass a second argument of True (the default is False): 'the "quick" &amp; &lt;brown&gt; fox' 'the &quot;quick&quot; &amp; &lt;brown&gt; fox' This seems to me to be dumb. The default option should be the safe one: that is, escape _all_ the potentially troublesome...
9
1744
by: jezonthenet | last post by:
I started using Python a couple of days ago - here are a few questions: * Doesn't the __main__() method automatically execute when I run my python program? * Only when I do an import of my test.py file within python and then run test.__main__() I can see where my bugs are. Is this correct? (right now this is my only way of running my python program and see where I have problems) * Once I've done an import and then I wish to make a...
0
292
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi all misters; I have an ASP.NET application, another program (EXE PowerBuilder) calls my ..aspx using http, by URL. The program "escape" url using javascript function: escape. when I use escape() javascript function, I get , for example, this: Observaciones%3DReenvio%20solicitado%3A%20cami%F3n%20co%F1o%20%
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.