Results 1 to 8 of 8
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Key Press Event and/or Key Up Event not firing as expected

    I have a text box with both key up and press event subs coded with:
    Code:
    If KeyCode = vbKeyDelete Then
    If I sweep the contents of the text box field, while displaying the containing form, NEITHER of the key events fire if I press the delete key. Unfortunately, the OnChange event doesn't make any distinction of deleting a single character within a string versus having swept the entire string.



    How can I detect the situation where an entire field has been swept (selected) and the delete key pressed?

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    You could try the before update event to see if the new value is null or '"" ZLS , then cancel it.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    BeforeUpdate event doesn't fire upon the pressing of the delete key.

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    This is a nasty one. I can detect the delete key press at the form level, see code:

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    
    If KeyCode = vbKeyDelete Then
        If Screen.ActiveControl.Name = "tbcyp" Then
            CYPDelKey = True
        Else
            CYPDelKey = False
        End If
    End If
    
    End Sub
    However, the problem persists in not being able to determine if the total content of the text box "tbcyp" was selected at the time the delete key was pressed. Both the bound table value and the content of the text box are yet unchanged as viewed in code, ONLY the screen view of the text box is seen as empty. Does Access provide access to what is poised as the update value?
    Last edited by GraeagleBill; 01-15-2018 at 08:52 PM.

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The before update event will fire only when you move the focus out of the textbox (tab, enter key, click elsewhere, etc).

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I could move the focus in the code I posted in #4 but that might absolutely be the wrong thing to do if the user is editing the string using a combination of the scroll keys and/or the delete key. The only time it would be appropriate would be if the entire string was selected, so I'm back where I started............ SIGH!

    Thanks John,
    Bill

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Does Access provide access to what is poised as the update value?
    Yes. You can use the .text property of the control to determine the the "tentative" value is. A better event to use might be the On Exit event, which you can cancel if all the text in the control has been deleted.

    Note: the .text property of a control is only accessible if the control has the focus.

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I guess there's a first time for everything............ using the "Text" property to see what "change" is pending did the trick for this caper.

    The App requires that when a payment field is deleted that a companion field containing a code also be visibly deleted. If one waits until the OnUpdate fires, one can certainly clear the companion field. BUT, the user won't see the companion deletion until they navigate away from the payment field which is unacceptable, hence the deletion has to have already been done.

    Below are the OnChange and OnUpdate events that handle the situation.

    Thanks John for the valuable lesson,
    Bill

    Code:
    Private Sub tbCYP_Change()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '*  With an change pending where the field has essentially been cleared, we also
    '*  need to clear the companion PC Code as well.  If that's the case, we update the
    '*  current record and clear any existing code.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    If Len(Me.tbCYP.Text & "") = 0 Then      'If poised to clear current payment
        If Me.Dirty Then Me.Dirty = False    'Save the record now
        Me.tbPCCode = Null                   'Clear the any code appearing
    End If
    
    End Sub
    
    Private Sub tbCYP_AfterUpdate()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '*  Similar to the launch of Allen Browne's pop-up calendar adjacent to the date control,
    ' * we want to open the popup form from which a Per Capita code can be selected.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    If Len(Me.PCCode & "") = 0 Then  'Don't know what it is... Null, Empty or zero length
        lngCurRecID = Me.MemID       'Save current record ID.  Popup needs global access.
        If Me.Dirty Then Me.Dirty = False   'We need this record updated now
        Me.tbPCCode.SetFocus                'Move to the PC Code box
        Call ShowPCCodes
    End If
    
    End Sub

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

Similar Threads

  1. Navigation subform event firing
    By Frank2306 in forum Forms
    Replies: 4
    Last Post: 05-11-2017, 07:10 AM
  2. Combo box On Dbl-Click event not firing
    By GraeagleBill in forum Forms
    Replies: 5
    Last Post: 12-26-2016, 06:45 PM
  3. Key Down event not firing
    By GraeagleBill in forum Programming
    Replies: 4
    Last Post: 11-18-2016, 12:45 AM
  4. tab control - firing a page on-click event
    By Chuck55 in forum Programming
    Replies: 7
    Last Post: 05-01-2012, 09:57 AM
  5. Form level mouseup event not firing
    By Philhoop in forum Forms
    Replies: 3
    Last Post: 07-22-2010, 09:41 AM

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