A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

KeyPress event



 
 
Thread Tools Display Modes
  #1  
Old August 26th, 2004, 03:47 PM
grep
external usenet poster
 
Posts: n/a
Default 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  
Old August 26th, 2004, 03:56 PM
grep
external usenet poster
 
Posts: n/a
Default

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  
Old August 26th, 2004, 06:22 PM
grep
external usenet poster
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 09:19 AM.


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