If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
KeyPress event
I had an interesting idea regarding a date field. I want to do a
Quicken-style date change thing... where you can press + or - to change the date in the field. I figured it would be easy, using the KeyPress event, but it's not working the way I thought. Here's what I tried: Private Sub Date_KeyPress(KeyAscii As Integer) Dim CurrentDate As Date CurrentDate = Me.Date Select Case KeyAscii Case 45 ' ANSI value of - Me.Date = DateAdd("d", -1, CurrentDate) Case 43 ' ANSI value of + Me.Date = DateAdd("d", 1, CurrentDate) End Select End Sub Any thoughts? grep |
#2
|
|||
|
|||
FYI, I figured out how to do it.
I noticed that the date value was actually incrementing, but that the string "-" or "+" were being left in the field (which was illegal). When I hit Esc, however, the date did increment. That led me to the following: Private Sub Date_KeyPress(KeyAscii As Integer) Dim CurrentDate As Date CurrentDate = Me.Date Select Case KeyAscii Case 45 Me.Date = DateAdd("d", -1, CurrentDate) Case 43 Me.Date = DateAdd("d", 1, CurrentDate) End Select SendKeys "{ESC}", True End Sub It works beautifully now. grep grep wrote: I had an interesting idea regarding a date field. I want to do a Quicken-style date change thing... where you can press + or - to change the date in the field. I figured it would be easy, using the KeyPress event, but it's not working the way I thought. Here's what I tried: Private Sub Date_KeyPress(KeyAscii As Integer) Dim CurrentDate As Date CurrentDate = Me.Date Select Case KeyAscii Case 45 ' ANSI value of - Me.Date = DateAdd("d", -1, CurrentDate) Case 43 ' ANSI value of + Me.Date = DateAdd("d", 1, CurrentDate) End Select End Sub Any thoughts? grep |
#3
|
|||
|
|||
Ok - I still need help. I tried to put it into a general module so I
could use it across many forms, and it's no longer working right. Specifically, it seems that the Sendkeys command throws it into a Stack Overflow. Here's what it look like now: Public Sub DatePush(MyKey As Integer) ' Increments date field using "+" and "-" Dim CurrentDate As Date Dim frmCurrentForm As Form Set frmCurrentForm = Screen.ActiveForm CurrentDate = frmCurrentForm.Date Select Case MyKey Case 45 frmCurrentForm.Date = DateAdd("d", -1, CurrentDate) Case 43 frmCurrentForm.Date = DateAdd("d", 1, CurrentDate) End Select SendKeys "{ESC}", True End Sub Any suggestions as to how to get around the problem? grep |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AfterUpdate event of Calendar Control in Access 2000 not firing as expected? | Gary | Using Forms | 3 | July 2nd, 2004 07:53 PM |
Need help with Access decision | aualias | General Discussion | 23 | June 21st, 2004 02:04 AM |
raise event of access control | vdavid | General Discussion | 3 | June 15th, 2004 03:35 PM |
raise event for access object | vdavid | Using Forms | 0 | June 14th, 2004 10:55 AM |
MsiInstaller Events on a Win2000 Terminal Server | jwgoerlich | Setup, Installing & Configuration | 0 | May 26th, 2004 06:30 PM |