ON SCREEN NUMERIC KEY PAD

K

Kamran

Hi,
is it possible to make a numeric pad on msaccess form so
that it enters the clicked number's value on to the field
that has focus like the quantity field? maybe by
using 'sendkeys' but how?
 
N

Nikos Yannacopoulos

Kamran,

I can think of a way to do this, here's the general idea:
Use a public variable to hold tha name of the control that was active when
the first numeric key was clicked;
Use the On Lost Focus event of all target numeric controls to store the
control name to the aforementioned variable;
Use a public variable to temporarily hold the numeric key sequence;
Use a local variable to hold the sequence of numeric keys clicked;
Use an OK button on the numeric keypad to transfer the number corresponding
to the keys pressed back to the control;

Here's some sample code to be inserted in the form's module.
Assumptions:
10 numeric keys called Key0 through Key9 (plus a KeyDec for decimals if you
need it)
OK key called KeyOK
Target numeric controls called TextA, TextB etc (change as required)

Public LastControl As String
Public NumString As String

Private Sub TextA_LostFocus()
LastControl = Me.ActiveControl.Name
NumString = ""
End Sub

Private Sub TextB_LostFocus()
LastControl = Me.ActiveControl.Name
NumString = ""
End Sub

Private Sub Key0_Click()
NumString = NumString & "0"
End Sub

Private Sub Key1_Click()
NumString = NumString & "1"
End Sub

....
....

Private Sub Key9_Click()
NumString = NumString & "9"
End Sub

Private Sub KeyDec_Click()
NumString = NumString & "."
End Sub

Private Sub KeyOK_Click()
Me.Controls(LastControl) = Val(NumString)
Me.Controls(LastControl).SetFocus
NumString = ""
End Sub

HTH,
Nikos

Here's some sample code, which assumes
 

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