Full Version: SendKeys function in form text field
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
zorki
Hi everybody,

I am looking for help, explanation of function SendKeys.

In my form I have text box in which I put an event, 'before update' like below:

Sub Form_beforeupdate(cancel as integer)
cancel = 1
sendkeys "{ESC}"
end sub


Pressing ESC key in above function should cause that eventual change in text box will not be accepted and changes will be undo. Unfortunately ESC key is not pressed and I need to do it manually from keyboard.

What is wrong? Can anybody help me how to resolve this problem?

Regards,
dannyseager
Firstly I (and many others) will advise you to avoid sendkeys. They can be unreliable and dangerous if the right window/form/control doesn't have focus....

The code you posted will simple not allow the user input to be saved as you cancel the update of the control with cancel=1... what are you trying to accomplish?
zorki
Thanks for reply,

Formula cancel=1 will not allow the user to make changes, but will not undo changes automatically. User will see error message and will have to press ESC. If he try to pas it over by closing form an error message will appear again and of course changes will be not saved.
However I want to avoid presenting error messages and making pressing ESC automatic.
dannyseager
try

Cancel = True
Me.ControlName.Undo
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.