Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendKeys {ESC} Not Working in Access 2002 1

Status
Not open for further replies.

jhaganjr

IS-IT--Management
Dec 11, 2002
62
US
Hi,

In Access 2000, running on Windows 2K, the following code in the BeforeUpdate field of a combo box prevents the update when the condition is met and then restores the original value in the box ...

If Not IsNull(Me.cboProduct.OldValue) Then
strMsg = "SORRY - THAT'S NOT ALLOWED!"
MsgBox strMsg
Cancel = True
SendKeys "{ESC}"
Exit Sub
End If

In Access 2002, running on Windows XP, the SendKeys statement does not function. Database is identical on each machine.

Anybody have any insight into this?

Thanks!
Joe
 
Have you tried to play with the SetFocus method just before using SendKeys ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV's right, but are you sure, you really need the ESC?
Cancel = True
SendKeys "{ESC}"

Sounds like double action..

YOu could also try with
Code:
DoCmd.CancelEvent

Depends on what you try to perform.

Cheers,
MakeItSo
 
Yeah. I've tried those and other variances in the code, but it always boils down to the same thing ...

In Access 2000, on a Win 2K machine, the event is canceled and the value in the combo box is restored to the value it was before the user made in a change. It works.

But in Access 2002, on a Win XP machine, with the exact same code in the exact same database, the event is canceled but the value in the combo box remains the value the user changed it to - instead of going back to its original value.

Wait ...

I didn't try to requery the combo box to see if that will restore the original value visually. Maybe that will work. I'll let you know ...

Joe
 
I solved it! Check it out ...

In the KeyDown event for the same control, I invoke a list drop down, so the list drops down when the user starts typing.

<cboProduct_KeyDown>
Me.cboProduct.DropDown

The "problem code" is ...

<cboProduct_BeforeUpdate>
If Not IsNull(Me.cboProduct.OldValue) Then
strMsg = "SORRY - THAT'S NOT ALLOWED!"
MsgBox strMsg
Cancel = True
SendKeys "{ESC}"
Exit Sub
End If

In Access 2000 this combination of events was fine. But in Access 2002 the SendKeys command in the BeforeUpdate event appears to invoke the KeyDown event, and instead of Escape restoring the old value, it drops down the list.

To fix it I moved the automatic drop down to the KeyUp event instead of KeyDown.

Now the BeforeUpdate event restores the original value to the control as intended, and the list automatically drops down when the user starts typing, as well.

Maybe you all can avoid some confusion if you move your databases from Access 2000 to 2002 with this experience. (It's certainly not the only quirk I've come across and probably won't be the last.)

Thanks for your help.
Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top