Results 1 to 3 of 3
  1. #1
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94

    Change event and input masks

    I have some forms where there's a couple of text boxes that are required, so before enabling a button I want to check both are filled. The way I do this is through the text box's change event, so that the button enables or disables while writing instead of having to leave the field. It's a pretty simple code, lets assume tb1 and tb2 are both mandatory:



    Code:
    Private Sub tb1_Change()
        If IsNull(Me.tb2) Or Me.tb1.Text = "" Then
            Me.button.Enabled = False
        Else
            Me.button.Enabled = True
        End If
    End Sub
    Thing is, in one of those forms, said text boxes have input masks. And apparently, the input mask messes with the change event of the text box, since the button enables once you start typing but don't disable when the text box is empty. I tried to change the code to enable the button when the text reaches the required length, but due to the input mask Len(tb1.text) always returns the length of the input mask.

    I'm thinking of dropping the change event and just use the afterupdate event or removing the input mask and adding a validation to the text box, but is there any way of doing it through the change event so the user doesn't need to leave the text box to see if the button is enabled without losing the visual cue of the input mask?

    Thanks in advance

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,807
    Not sure I follow completely. Once the text is entered, how is the button activated? If that is by clicking on it, you've just left the control/field so what's the point of coding to try to get around that? Besides, change event fires for every key press on that control - not always a good thing. Then, I can enter A and backspace to remove and now the button is enabled. Too late to perform any evaluation on what's in the control because now I can click anyway. You're probably better off using BeforeUpdate to validate contents, and cancel the event if the entry doesn't pass validation tests. If it passes, enable the button.
    Last edited by Micron; 04-18-2024 at 10:11 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    The idea behind using the change event is giving the user a more clear indicator of when the data is ready to be sent. If they're typing on the text box, I'd like to enable the button once the text has met a desired criteria (in the other forms is just having some text, no length required. In this case, they have to meet a length requirement, thus the input mask to give further visual clues).

    Then, I can enter A and backspace to remove and now the button is enabled.
    In this case, due to the input mask, that is correct. That's exactly what I want to correct, ideally not just through a beforeupdate check, but getting the button to disable again as it does without an input mask. Without the input mask the button would disable again when deleting the text so you wouldn't be able to click it.

    If I use beforeupdate to check the criteria and enable the button (or afterupdate just for the latter) the button won't enable until leaving the text box. I know it's a small nuisance, but I'd like to mantain the enablement of the button while they type, it's not like a small check every time the user types in a small box designed to enter short texts is gonna clog the system.

    Then again, if the input mask makes it impossible to do it through the change event, I'll definitely go for the beforeupdate event.

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

Similar Threads

  1. Question on input masks
    By MikeFanch in forum Access
    Replies: 2
    Last Post: 05-23-2014, 09:03 PM
  2. Input Masks
    By jlgray0127 in forum Forms
    Replies: 3
    Last Post: 12-14-2013, 12:50 PM
  3. Input Masks
    By ICTTeacher in forum Database Design
    Replies: 1
    Last Post: 11-07-2013, 10:08 AM
  4. Validation and Input masks
    By Santi in forum Access
    Replies: 3
    Last Post: 03-26-2009, 10:53 AM
  5. can a field have 2 different input masks
    By cjamps in forum Database Design
    Replies: 1
    Last Post: 03-21-2009, 02:47 PM

Tags for this Thread

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