Results 1 to 5 of 5
  1. #1
    Opid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    24

    Make + and - adjust date in field.

    Hello everyone,

    I am trying to make the + - (numpad) adjust the date of the current text field. The problem I am having is I believe the input mask intercepts the keypress and my keypress event is never fired. Here is my code:
    Code:
    Private Sub LeaseDate_KeyDown(KeyCode As Integer, Shift As Integer)If (KeyAscii = 107) Then
    LeaseDate = DateAdd("d", 1, LeaseDate)
    End If
    
    
    If (KeyAscii = 109) Then
    LeaseDate = DateAdd("d", -1, LeaseDate)
    End If
    End Sub
    Access makes the ding noise when I try and press + and -



    Thanks in advance

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    For starters you have your codes wrong, for seconds you need to reset KeyAscii. This works in a brief test:

    Code:
      If (KeyAscii = 43) Then
        KeyAscii = 0
        Date_in_Service = DateAdd("d", 1, Date_in_Service)
      End If
    
    
      If (KeyAscii = 45) Then
        KeyAscii = 0
        Date_in_Service = DateAdd("d", -1, Date_in_Service)
      End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Opid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    24
    Thanks for the response ,

    I tried switching out the codes and resetting the Keyascii but access still dings at me. I think the input mask is catching the key event...

  4. #4
    Opid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    24
    Figured it out. Needs to be in KeyPressed event not KeyDown. Thank you pbaldy!
    Code:
    Private Sub LeaseDate_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 43) Then
        KeyAscii = 0
        LeaseDate = DateAdd("d", 1, LeaseDate)
      End If
      If (KeyAscii = 45) Then
        KeyAscii = 0
        LeaseDate = DateAdd("d", -1, LeaseDate)
      End If
    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Sorry, I should have noticed the event. Glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-31-2012, 07:53 AM
  2. Replies: 2
    Last Post: 02-22-2012, 05:10 PM
  3. Make new field based on previous field's answer
    By VictoriaAlbert in forum Access
    Replies: 1
    Last Post: 04-11-2011, 09:54 PM
  4. Replies: 2
    Last Post: 06-18-2006, 10:50 PM
  5. Replies: 1
    Last Post: 12-09-2005, 10:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums