Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use keys plus/minus to increase or decrease number? 1

Status
Not open for further replies.

Crownknox

Technical User
Apr 27, 2000
25
0
0
US
I have several fields in a form where the default value is usually the date. But i often have to change it. I am wondering if it is possible that if the plus key or minus key on the number pad of the keboard are pressed it will add 1 to the date or subtract one to the date.

Example

Date = 12/04/01

If plus (+) key is pressed then 12/05/01
If minus (-) key is pressed then 12/03/01

Is this possible?

I would appreciate any help!
Thanks

 
Go to the design view for your form.
Right click on the control that you want this to happen for.
Make sure that the format is set to short date.
Go to events and next to the on key down event type event procedure.
Then click on the ... button.
When the code window opens up paste the code below in between where it says private sub and end sub.
Where the code you pasted says text1 type the name of your textbox.
Then save and close.

Code:
    If KeyCode = 107 Then
        Me.Text1 = Me.Text1 + 1
        KeyCode = 0
    ElseIf KeyCode = 109 Then
        Me.Text1 = Me.Text1 - 1
        KeyCode = 0
    End If[B] The hardest questions always have the easiest answers.
 
107 == vbkeyadd

109 == vbkeysubtract

would make for easier reading / documentation MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top