Determine the key pressed without the procedure...

Ecron

Registered User.
Local time
Yesterday, 21:37
Joined
Aug 31, 2006
Messages
58
Hello,

I would like to determine the key pressed without using the actual event on a form.

When looking at the event I can see they have created an integer that stores the ASCII value, so my question is how do I store the key pressed into an integer of my own making without the event?

Thanks!
 
hmm.

Maybe if I ask a different question?:rolleyes:

Is it possible to run a module on the event: On Key Down and use the KeyCode integer in that event within the created module?

Thanks again!
 
Ecron:

A couple of things here -

1.
Is it possible to run a module on the event
You don't run a module. A module contains subroutines (Sub) or functions (Function) which you run.

2. You can call a sub or a function from any event. Whether it works or not depends on what you are trying to do and in which event.

3.
When looking at the event I can see they have created an integer that stores the ASCII value
"Who" creates an integer that stores the ASCII value? The KeyDown event is something that occurs when you press a key, and the key that is pressed is shown as a constant (KeyCode which can be translated into it's ASCII value).

So, what do you want to actually accomplish? The brief answer to your question is YES you can do something based on the key pressed.
 
If that's the case,

I'm having trouble with it! -_-

My module just uses the assumed integer named KeyCode and runs an if statement to determine whether or not a specific key is being pressed, while on the main form, the KeyPress event procedure directs to the module I have created.

Module source is:
Code:
Public Function KeyDown()
    Dim str As String
        MsgBox "running keydown"
    
    If KeyCode = vbKeyN Then
        MsgBox "n pressed"

    End If
End Function

the integer KeyCode is NOT initiated... which was the source of my main question.:confused:
 
(sorry for lag-time in response, dial-up user! blehg)

Thanks boblarson,

I am aware of the differences between modules and the routines involved in them. I'm sorry to confuse everyone when mixing up the module and a function I'm still not used to it too well and have made mistakes in naming functions and modules the same.

The last post then refers to my function, and NOT the module!
 
First of all your function is not really a function but a sub as it isn't really returning anything. Also, your function has
Code:
Dim str As String
but it isn't being used. And where is vbKeyN coming from? There's nothing there for it. Also, your second message box is flawed in that you are saying
"n pressed" and that's exactly what it will say "n pressed" not the number pressed.

Try this instead:
Code:
Public Function MyKeyDown(intKeyPressed As Integer) as Boolean
         MsgBox intKeyPressed & " pressed"
         MyKeyDown = True
End Function
and that will show you (if you call it properly from your KeyDown event) which keycode is being used

In your KeyDown event you would place
Code:
MyKeyDown KeyCode

and don't name your function KeyDown as it is a reserverd Access Keyword.
 
:o

Thank you.

The str declared was going to be used after I had determined whether a key was pressed (once I got the function working).

Also, is there a way to bypass the [event procedure] when attempting to test for a KeyDown or KeyPress event?

As in, creating your OWN KeyDown function that doesn't have to use the KeyCode in access' event?
 
vbKeyN is a constant in VBA which contains the integer 78 = N
n on the other hand = 110...
It is much easier on the eyes if you use Asc("N") =

and don't name your function KeyDown as it is a reserverd Access Keyword.
Hail to that... as well as many other words like Date, etc.

You have to use the event(s) that is what they are there for... it actually makes life easier once you are used to it...
 
heh.

Well, I guess that answers my question. I was just trying to avoid having to change the Event Procedure on multiple forms when I could just change the function.

Thank you both very much, you've been a great help and hopefully my ignorance hasn't disturbed you!
 

Users who are viewing this thread

Back
Top Bottom