Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Change date with KeyDown

The following code changes a date in a form text box like this:
txtDate.Text = Format(Date, "mm/dd")
with left and right arrows.
Private Sub txtDate_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Dim sDate As String
Dim v As Integer, dte As Date
Select Case KeyCode
Case 37 ' Left
v = -1
Case 39 ' Right
v = 1
Case Else
v = 0
End Select
sDate = txtDate.Text
If InStr(sDate, ",") Then
sDate = Trim(Right(sDate, Len(sDate) - InStr(sDate, ",")))
End If
If IsDate(sDate) And v < 0 Then
dte = CDate(sDate)
dte = dte + v
txtDate = Format(dte, "mm/dd")
End If
End Sub

Can this be adapted to change a Time value formatted thus: txtTime.text
= Format(Now(), "h:mm AM/PM") by 15 minute increments.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Change date with KeyDown

This worked for me:

Private Sub txtDate_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Dim sDate As String
Dim v As Integer, dte As Date
Select Case KeyCode
Case 37 ' Left
v = -1
Case 39 ' Right
v = 1
Case Else
v = 0
End Select
sDate = txtDate.Text
If InStr(sDate, ",") Then
sDate = Trim(Right(sDate, Len(sDate) - InStr(sDate, ",")))
End If
If IsDate(sDate) And v < 0 Then
dte = CDate(sDate)
dte = dte + v*TimeValue("00:15")
txtDate = Format(dte, "hh:mm")
End If
End Sub

--
Regards,
Tom Ogilvy


"John Pierce" wrote in message
oups.com...
The following code changes a date in a form text box like this:
txtDate.Text = Format(Date, "mm/dd")
with left and right arrows.
Private Sub txtDate_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Dim sDate As String
Dim v As Integer, dte As Date
Select Case KeyCode
Case 37 ' Left
v = -1
Case 39 ' Right
v = 1
Case Else
v = 0
End Select
sDate = txtDate.Text
If InStr(sDate, ",") Then
sDate = Trim(Right(sDate, Len(sDate) - InStr(sDate, ",")))
End If
If IsDate(sDate) And v < 0 Then
dte = CDate(sDate)
dte = dte + v
txtDate = Format(dte, "mm/dd")
End If
End Sub

Can this be adapted to change a Time value formatted thus: txtTime.text
= Format(Now(), "h:mm AM/PM") by 15 minute increments.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
keydown event Peter T Excel Programming 0 April 18th 05 02:03 PM
keydown event K Dales[_2_] Excel Programming 0 April 18th 05 12:46 PM
KeyDown event in sheet Peter Wallin Excel Programming 1 February 27th 04 10:25 AM
KeyDown / KeyPress Events Barry Pettis[_2_] Excel Programming 1 February 12th 04 05:09 AM
keydown event jim c. Excel Programming 1 October 10th 03 03:16 AM


All times are GMT +1. The time now is 12:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"