Code.GeekInterview.com
 
Code Samples MS Access
 

Increment and Decrement Date Value using hot Keys + / -


Code ResourceAuthor: Shivanna  

Difficulty Level:

Published: 25th May 2007   Read: 3852 times  

Filed in: MS Access
Add Comment


 

 

Sponsored Links


 

 

There are situations where data entry operators need to change date value.  This custom made function helps the users to quickly edit the date field using plus key (+) to increment the date value by one day and minus key (-) to decrement the date value by 1 day. The function provided below takes in date value as one of its argument along with keyCode and Shift, both of which are directly transfered from the OnKeyDown event procedure parameters. This function has to be called from the date field OnKeyDown event.

 


Sample Code
  1.  
  2. Public Function PDate(PObj As Object, KeyCode As Integer, Shift As Integer)
  3. If KeyCode = vbKeyAdd Then
  4.     If Shift = 2 Then
  5.         PObj = DateAdd("m", 1, PObj)
  6.         KeyCode = 0
  7.     Else
  8.         PObj = DateAdd("d", 1, PObj)
  9.         KeyCode = 0
  10.     End If
  11. End If
  12.  
  13. If KeyCode = vbKeySubtract Then
  14.     If Shift = 2 Then
  15.         PObj = DateAdd("m", -1, PObj)
  16.         KeyCode = 0
  17.     Else
  18.         PObj = DateAdd("d", -1, PObj)
  19.         KeyCode = 0
  20.     End If
  21. End If
  22. End Function
  23.  
  24. Example for calling PDate function
  25. Private Sub Invoice_Date_KeyDown(KeyCode As Integer, Shift As Integer)
  26.     PDate Me.Invoice_Date, KeyCode, Shift
  27. End Sub
  28.  
  29. Whenever user hits + or - in the Invoice_Date field, the value of Invoice Date changes accordingly
  30.  
Copyright GeekInterview.com


Next: Show Print Preview Option before printing


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. Lokesh M11291
2. Shivanna6124
3. Rajani4933

Active Coders

# Coder NameCodes
1. Shivanna2
2. Lokesh M2
3. Rajani1

Refined Tags