Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Can't catch enter key in form.keypress event
Hi,

Do you have any idea why a form keypress event would stop to catch the
"enter" key?

Even if I run this:

Private Sub Form_KeyPress(KeyAscii As Integer)
msgbox KeyAscii
End Sub

The "enter" key is not catched.....

In my form I don't have any control who could disable the enter key event.

Any suggestion would be appreciated.

Marty

Report this thread to moderator Post Follow-up to this message
Old Post
Marty
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
"Marty" <reply@to.forum> wrote in message
news:FeC6d.2433$eq.843@edtnps84
> Hi,
>
> Do you have any idea why a form keypress event would stop to catch the
> "enter" key?
>
> Even if I run this:
>
> Private Sub Form_KeyPress(KeyAscii As Integer)
>        msgbox KeyAscii
> End Sub
>
> The "enter" key is not catched.....
>
> In my form I don't have any control who could disable the enter key
> event.

Do you have a command button with .Default=True ?

--
Reply to the group so all can participate
VB.Net... just say "No"


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
>
> Do you have a command button with .Default=True ?
>


No, I don't.

Report this thread to moderator Post Follow-up to this message
Old Post
Marty
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
The KeyPress event seems to favor controls.  I just use the KeyPress event o
f
the control I know will have the focus.

"Marty" wrote:
 
>
>
> No, I don't.
>

Report this thread to moderator Post Follow-up to this message
Old Post
Charlie
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
> "enter" key?
>
> Even if I run this:
>
> Private Sub Form_KeyPress(KeyAscii As Integer)
>        msgbox KeyAscii
> End Sub
>
> The "enter" key is not catched.....
>
> In my form I don't have any control who could disable the enter key
event.

Do you have the form's KeyPreview property set to True? If not, try
setting it to that.

Rick - MVP


Report this thread to moderator Post Follow-up to this message
Old Post
Rick Rothstein
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
"Marty" <reply@to.forum> wrote in message
news:XtC6d.2436$eq.1382@edtnps84 
>
> No, I don't.

The form's KeyPreview property is True?  do the KeyDown and/or KeyUp events
fire?

what control types are on the form?

--
Reply to the group so all can participate
VB.Net... just say "No"


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
Yes the form' KeyPreview = True

I did another test.

sub Form_load()
btnMyEvent.Default = True          'Command button control
btnMyEvent.getFocus = True
end sub

Private Sub btnMyEvent_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub

This won't catch the "enter" key.  All other key are catched...


Report this thread to moderator Post Follow-up to this message
Old Post
Marty
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
"Marty" <reply@to.forum> wrote in message
news:rMC6d.2449$eq.443@edtnps84
> Yes the form' KeyPreview = True
>
> I did another test.
>
> sub Form_load()
>      btnMyEvent.Default = True          'Command button control
>      btnMyEvent.getFocus = True

there is no .GetFocus property on command buttons in VB... are you using
VB.Net or VB 2005 and confusing it with VB6 and/or earlier versions?  If so,
you are asking in the wrong newsgroup and need to find one with 'dotnet' in
the name.

--
Reply to the group so all can participate
VB.Net... just say "No"


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
My mistake,

I mean :
btnMyEvent.SetFocus

instead of
btnMyEvent.GetFocus



Bob Butler wrote:

> "Marty" <reply@to.forum> wrote in message
> news:rMC6d.2449$eq.443@edtnps84
> 
>
>
> there is no .GetFocus property on command buttons in VB... are you using
> VB.Net or VB 2005 and confusing it with VB6 and/or earlier versions?  If s
o,
> you are asking in the wrong newsgroup and need to find one with 'dotnet' i
n
> the name.
>

Report this thread to moderator Post Follow-up to this message
Old Post
Marty
09-29-04 08:55 PM


Re: Can't catch enter key in form.keypress event
"Marty" <reply@to.forum> wrote in message news:cYC6d.2452$eq.10@edtnps84
> My mistake,
>
> I mean :
> btnMyEvent.SetFocus
>
> instead of
> btnMyEvent.GetFocus

No problem; I just tried it and apparently when a command button has the
focus the KeyXXXX events are not fired for ENTER.  It also doesn't fire the
default command button unless that's the one that has the focus.  I don't
remember running into that before.

--
Reply to the group so all can participate
VB.Net... just say "No"


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
09-29-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Pages (3): [1] 2 3 »
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:43 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.