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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

increment and decrement date field

Status
Not open for further replies.

Bill0722

Technical User
Jul 1, 2006
29
US
Is there anyway I can format the date field on a form to increment and decrement using the + and - keys.

Thanks,

Bill
 
I would do it with a spin button. Remeber set the min value to less than zero.

Code:
Private Sub SpinButton4_Updated(Code As Integer)
  'MsgBox Me.SpinButton4
  If IsDate(Me.Text5) Then
    Me.Text5 = CDate(Me.Text5) + Me.SpinButton4
  End If
  Me.SpinButton4.Value = 0
End Sub
With Remou's suggestion.
Code:
Private Sub Text5_KeyPress(KeyAscii As Integer)
  If KeyAscii = 43 Then
      Me.Text5.Text = CDate(ActiveControl.oldValue) + 1
      DoCmd.CancelEvent
   ElseIf KeyAscii = 45 Then
      Me.Text5.Text = CDate(ActiveControl.oldValue) - 1
      DoCmd.CancelEvent
    End If
    Me.Refresh
End Sub
I found this a little awkward. Easy to hit something besides a plus or minus.
 
put the refresh inside the if

Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 43 Then
Me.Text5.Text = CDate(ActiveControl.oldValue) + 1
DoCmd.CancelEvent
Me.Refresh
ElseIf KeyAscii = 45 Then
Me.Text5.Text = CDate(ActiveControl.oldValue) - 1
DoCmd.CancelEvent
Me.Refresh
End If

End Sub
 
MajP said:
[blue]I would do it with a spin button.[/blue]
Well . . . [blue]Bill0722[/blue] didn't ask for a spin button, but . . . [blue]+/- control keys of the value![/blue] . . . Ya Think?

[blue]Bill0722[/blue] . . . have alook at the [blue]KeyPress[/blue] event! . . .

Calvin.gif
See Ya! . . . . . .
 
AceMan,
What is the deal? You seem a little testy. I suggested a spin button because I found it awkward with the +/-, and provided some code to demonstrate the key press event. If that suggestion bothers you then provide some code
YA THINK?
 
MajP . . .

Its not what ya think! . . . [blue]Respect for any post made by you remains intact! . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top