Keypad for POS application

RomeoJuliet

Registered User.
Local time
Today, 13:03
Joined
Nov 20, 2008
Messages
23
I am writing a POS application and need to make an on-screen keypad more efficient. I want to allow the user to 'click' each of the number buttons by pressing an actual number key on the keyboard, as well as by clicking the button controls.

I have changed KeyPreview to Yes in the form's properties, and written this code for the On Keypress event:
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
   Select Case KeyAscii
      Case vbKey1 Or vbKeyNumpad1
         Me.Command0.SetFocus '1 control on form
         SendKeys "{enter}"
      Case vbKey2 Or vbKeyNumpad2
         Me.Command1.SetFocus '2 control on form
         SendKeys "{enter}"
      Case vbKey3 Or vbKeyNumpad3
         Me.Command2.SetFocus '3 control on form
         SendKeys "{enter}"
      Case vbKey4 Or vbKeyNumpad4
         Me.Command3.SetFocus '4 control on form
         SendKeys "{enter}"
      Case vbKey5 Or vbKeyNumpad5
         Me.Command4.SetFocus '5 control on form
         SendKeys "{enter}"
      Case vbKey6 Or vbKeyNumpad6
         Me.Command5.SetFocus '6 control on form
         SendKeys "{enter}"
      Case vbKey7 Or vbKeyNumpad7
         Me.Command6.SetFocus '7 control on form
         SendKeys "{enter}"
      Case vbKey8 Or vbKeyNumpad8
         Me.Command7.SetFocus '8 control on form
         SendKeys "{enter}"
      Case vbKey9 Or vbKeyNumpad9
         Me.Command8.SetFocus '9 control on form
         SendKeys "{enter}"
      Case vbKey0 Or vbKeyNumpad0
         Me.Command9.SetFocus '0 control on form
         SendKeys "{enter}"
   End Select
End Sub
Unfortunately, nothing happens: the focus doesn't change as I press different number keys, and no event appears to take place.

Can anyone help?

Many thanks
Mike.
 
Thanks Coach, but as I understand it the example you've given is taking click events and producing keyboard equivalents, which is the reverse of what I'm trying to achieve.

... or am I missing something obvious?

Thanks
Mike.
 
Mike:

Without seeing the application:

A few things:

1) Did you check that the numlock is on?
2) I usually avoid using Sendkeys as many Access users find it to be unreliable. What I do if I want to force a button to be clicked is to call the click method of that button. For example, instead of

Me.Command0.SetFocus '1 control on form
SendKeys "{enter}"

I would use:

Me.Command0_Click

SHADOW
 
Thanks Shadow. This is how my code looks now:
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
   Select Case KeyAscii
      Case vbKey1 Or vbKeyNumpad1
         Me.Command0_Click
      Case vbKey2 Or vbKeyNumpad2
         Me.Command1_Click
      Case vbKey3 Or vbKeyNumpad3
         Me.Command2_Click
      Case vbKey4 Or vbKeyNumpad4
         Me.Command3_Click
      Case vbKey5 Or vbKeyNumpad5
         Me.Command4_Click
      Case vbKey6 Or vbKeyNumpad6
         Me.Command5_Click
      Case vbKey7 Or vbKeyNumpad7
         Me.Command6_Click
      Case vbKey8 Or vbKeyNumpad8
         Me.Command7_Click
      Case vbKey9 Or vbKeyNumpad9
         Me.Command8_Click
      Case vbKey0 Or vbKeyNumpad0
         Me.Command9_Click
   End Select
End Sub
Now, with the numlock off, the keypad keys do what they always did (eg the 4/left arrow key moves through the controls in reverse tab order). However, with numlock on, pressing any key results in "Compile error: method or data member not found", with the debug highlight on
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)

Any clues?

Thanks
Mike.
 
I also want to point out that when I have two possibilities in a select, I usually use:

Case a, b

rather than

Case a or b

I am not sure that the OR works but you have to check with one of the forum experts.

Lastly, are you sure that each button HAS a click event? Sorry but this is the most obvious.

SHADOW
 
Shadow, I've replaced Or so that now I have (for instance) "Case vbKey1, vbKeyNumpad1". However, the result is the same.

... and yes, each button definitely has a click event; the form has been in use for a while.

Thanks for all your help - any more would be welcomed!

Mike.
 
I'm outta answers! Maybe someone else can advise or if you're willing to post the database it may help someone find something.

SHADOW
 
No problem! See attached - the form in question is KeypadFrm.

Thanks
Mike.
 

Attachments

No problem! See attached - the form in question is KeypadFrm.

Thanks
Mike.

Mike

You set your button commands to Private! You have to set them to public if you want this to work.

Example:

Public Sub Command0_Click()

Rather than

Private Sub Command0_Click()

SHADOW
 
Many thanks Shadow, all working perfectly now. I wouldn't have got there without you.

Mike.
 
Many thanks Shadow, all working perfectly now. I wouldn't have got there without you.

Mike.

Most welcome. I'm glad I could help people just as many people on this forum have helped me in the past.

SHADOW
 

Users who are viewing this thread

Back
Top Bottom