Keyboard event

J

Jezebel

There's no equivalent of the form-level KeyPress or KeyDown events, if
that's what you're asking.
 
W

wschiro

I have a word doc with form fields in a table and would like to know when the
key is pressed on the key board.

I am trying this code in a module


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox "code working", vbCritical
End Sub

But no luck. I am new to VBA and I am not sure what I am doing wrong.
 
A

Anne Troy

So every time the person hits the keyboard, you want to run code? I think
you're asking for trouble. This would like crash if someone like me types
into it. Sometimes, it's best to describe your goal instead of trying to
figure out your method. Many things have been done before, and many have
been attempted before. Likely, someone can provide the best method before
you tear your hair out working on yours. :)
*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com
 
J

Jezebel

That code is intended for UserForms (ie forms created in VBA itself) not for
document forms. There's no easy way to trap keyboard events in the document.
It is technically possibly through API calls -- it involves callback
functions to monitor the message queue -- but it renders Word pretty well
unusable unless you're prepared to put up with serious latency between
keystrokes.

What are you actually trying to do? WHY do you want to monitor the user
entry key-by-key?
 
W

wschiro

Thanks for all the good input. I have a form field in a table. I have the
table cell height fixed (exactly) so does not change. I have the maximum
length set also. I can not use a mono space font. If you hit the enter key
the text can disappear. Since I can not use a mono space font a capital
letters takes up more space. If I set the maximum length to 70 and this
fills up my cell completely this works fine but if the user uses lower case
then the text will not fill up the cell. What I am trying to do is set up
this form so that the user can only type information in the cell and it not
spill over (disappear) and fills up the entire cell.
 
J

Jezebel

Since trapping keystrokes is not an option, this is not a problem that can
be solved in this way. Simplest approach is just to ignore it: ultimately
it's always up to the user. If they fill the cell to over-flowing, so be it.
 

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