Help with Keypress 
Author Message
 Help with Keypress

Need to trap for enter and sendkey left tab or tab.

Private Sub FListItem_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
        if Chr(KeyAscii) = "11" sendkey Chr "9"
End Sub

--
Carl & Linda Brehm
Lake Lafourche Bird House
Keets, Tiels, GN & Red Lories, Quakers
Plum Head, Mitred Conures, TAG's
Bird Toys, Cages, Feed & Supplies

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.*-*-*.com/ ).
Version: 6.0.408 / Virus Database: 230 - Release Date: 10/24/2002



Thu, 05 May 2005 05:06:43 GMT  
 Help with Keypress
Another thought is to just redefine keyascii.  I didn't try it with tab and
enter and so forth, but it worked with letters:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > 65 And KeyAscii <= 90 Then
KeyAscii = 65
End If
End Sub

Regards,
Tom Ogilvy


Quote:


> >Need to trap for enter and sendkey left tab or tab.

> >Private Sub FListItem_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
> >        if Chr(KeyAscii) = "11" sendkey Chr "9"
> >End Sub

> I think this is what you're after:

> Private Sub FListItem_KeyPress(ByVal KeyAscii  _
>  As MSForms.ReturnInteger)

> If KeyAscii = vbKeyReturn Then
>    SendKeys "{Tab}"
> End If

> End Sub

> However Sendkeys is generally regarded as a buggy P.O.S. If your
> intention is to move to another control on the form (I'm assuming
> textboxes here, but the principle still holds for any control), it
> would be better to just set the focus to the other control rather than
> simulating the user tabbing to it. For example:

> Private Sub FListItem_KeyPress(ByVal KeyAscii As
> MSForms.ReturnInteger)

> If KeyAscii = vbKeyReturn Then
>     TextBox2.SetFocus
> End If

> End Sub

> ---------------------------------------------------------
> Hank Scorpio
> scorpionet who hates spam is at iprimus.com.au (You know what to do.)
> * Please keep all replies in this Newsgroup. Thanks! *



Thu, 05 May 2005 06:06:49 GMT  
 Help with Keypress


Quote:
>Need to trap for enter and sendkey left tab or tab.

>Private Sub FListItem_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
>        if Chr(KeyAscii) = "11" sendkey Chr "9"
>End Sub

I think this is what you're after:

Private Sub FListItem_KeyPress(ByVal KeyAscii  _
 As MSForms.ReturnInteger)

If KeyAscii = vbKeyReturn Then
   SendKeys "{Tab}"
End If

End Sub

However Sendkeys is generally regarded as a buggy P.O.S. If your
intention is to move to another control on the form (I'm assuming
textboxes here, but the principle still holds for any control), it
would be better to just set the focus to the other control rather than
simulating the user tabbing to it. For example:

Private Sub FListItem_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)

If KeyAscii = vbKeyReturn Then
    TextBox2.SetFocus
End If

End Sub

---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is at iprimus.com.au (You know what to do.)
* Please keep all replies in this Newsgroup. Thanks! *



Thu, 05 May 2005 05:45:00 GMT  
 Help with Keypress
Carl

Use KeyDown instead of Keypress:

Private Sub ListBox1_KeyDown(ByVal _
    KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then KeyCode = 9
End Sub

HTH. Best wishes Harald


Quote:
> Problem was the enter key does nothing in a listbox, but in a textbox it
> assigns the value you entered and sets focus to the next field in tab stop
> order.

> Thanks this worked

> Private Sub FListItem_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
> If KeyAscii = vbKeyReturn Then 'traps enter key pressed
>     FListItem.Value = FListItem.ListIndex    ' assigns the value selected
to
> the listbox.value
>     FItemPrice.SetFocus   'moves focus to next  textbox
> End If
> End Sub

> Now to make it generic so it can be used in all list boxes
> Or would doing so just slow down the program?
> Which way would be the most effecient? Generic or just the code like
above?

> Hmm...

> Private Sub FListItem_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
>     handle_listbox_enter "FListItem"
> End Sub

> Sub handle_listbox_enter(ByVal Listname as String)

> Listname.Value = Listname.ListIndex    ' assigns the value selected to the
> listbox.value
>     FItemPrice.SetFocus   'moves focus to next  textbox
> End Sub

> returns Variable not defined on listname
> Ideas?

> --
> Carl & Linda Brehm
> Lake Lafourche Bird House
> Keets, Tiels, GN & Red Lories, Quakers
> Plum Head, Mitred Conures, TAG's
> Bird Toys, Cages, Feed & Supplies




> > >Need to trap for enter and sendkey left tab or tab.

> > >Private Sub FListItem_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
> > >        if Chr(KeyAscii) = "11" sendkey Chr "9"
> > >End Sub

> > I think this is what you're after:

> > Private Sub FListItem_KeyPress(ByVal KeyAscii  _
> >  As MSForms.ReturnInteger)

> > If KeyAscii = vbKeyReturn Then
> >    SendKeys "{Tab}"
> > End If

> > End Sub

> > However Sendkeys is generally regarded as a buggy P.O.S. If your
> > intention is to move to another control on the form (I'm assuming
> > textboxes here, but the principle still holds for any control), it
> > would be better to just set the focus to the other control rather than
> > simulating the user tabbing to it. For example:

> > Private Sub FListItem_KeyPress(ByVal KeyAscii As
> > MSForms.ReturnInteger)

> > If KeyAscii = vbKeyReturn Then
> >     TextBox2.SetFocus
> > End If

> > End Sub

> > ---------------------------------------------------------
> > Hank Scorpio
> > scorpionet who hates spam is at iprimus.com.au (You know what to do.)
> > * Please keep all replies in this Newsgroup. Thanks! *

> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.408 / Virus Database: 230 - Release Date: 10/24/2002



Thu, 05 May 2005 18:40:43 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help with KeyPress command phrasing

2. Trapping Onkey or Keypress in UserForm : please help

3. repost of KeyPress Problem --- Help!

4. In vbs exist the keypress event

5. Keypress event

6. Disabling shift keypress that prevents code execution

7. Keypress Counter

8. Capture keypress

9. Exit Loop on keypress?

10. Keypress


 
Powered by phpBB® Forum Software © phpBB Group