KeyAscii (Unidentifyed variable)

N

Niklas Östergren

Hi!

I have discovered Allen Browne hompage containing one function in free
MS-Access tips which I´d like to use (see below). But I keep getting an
error saying:

- Unidentifyed variable for <KeyAscii>
Anyone have a clue of why and what I do about this?

TIA!
// Niklas

================================================
Select Case KeyAscii
Case 43 ' Plus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + 1
Case 45 ' Minus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl - 1
End Select
=================================================
 
N

Niklas Östergren

Sorry I forgot to tell you that I´m running Access 2002 and I have following
references checked:

- Visual Basic For Aplications
- Microsoft Access 10.0 Object Library
- Microsoft DAO 3.6 Object Library

And a mdb-file:
- ErrorLoggingXP

TIA!
// Niklas
 
D

Douglas J. Steele

What event are you putting that code into? It's meant to go into a KeyPress
event, in which case KeyAscii is the value passed to the routine.
 
N

Niklas Östergren

OK!

Thanks Douglas, now it works! At the beginning I put the code in a controls
KeyDown_Event but now I have it in KeyPress_Event! I think I have to read
the instructions a little bit better in the future. :)

Thanks!

// Niklas
 
M

Mike Labosh

If memory serves me correctly, I believe this should clear it up:

KeyPress Event: When the user presses a key and releases it, you get
KeyAscii, th eASCII value of the key that the user pressed and released.
The event is sent to your application *after the release*

KeyDown Event: When the key is *on its way down* as the user presses it, you
get some other kind of value KeyCode? that represents the value generated by
the keyboard controller at Interrupt 1. I am suffering from supreme lack of
sleep, but I think this is what the Windows SDK calls a "Virtual Key" when
it defines constants like VKEY_F1.

KeyUp Event: When the key is *on its way up* as the user releases it, you
get the same value as in the
KeyDown event above.

So as the user is typing, you can actually intercept 3 different events from
each keystroke. I forget what the deal is with auto-repeat of keystrokes
(when a user presses and holds a key), but I think that generates lots of
KeyDown events.
 
N

Niklas Östergren

Hi Mike!

Thank´s a lot for a good explanation. I´ll try to keep this in mind. On the
other hand there has to be something about this in the helpfile, so maby I
don´t need to remember everything.

Thanks again!

// Niklas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top