Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009
    Posts
    2

    Unanswered: On Change event requiring a control source

    Hi there,

    I have created a relationship on a form between a text box and a button that is affected by an On Dirty event as follows:

    Private Sub txtDiscID_Dirty(Cancel As Integer)
    Me.btnClearForm.Enabled = True
    End Sub

    If I bound the text field to a table, the sub routine works fine, but if the text field is undefined, then the trigger does not occur and the button, which I prefer to enable only when there is something to clear, remains disabled.

    You might say, well then re-establish the control source and move on with your life. Unfortunately, another problem would emerge if I did this.

    Am I missing something?

  2. #2
    Join Date
    Jan 2012
    Posts
    97
    This is because the OnDirty property tests if the value of the field has been modified and an unbound field has nothing to test against.

    Is the form itself bound?

    Would running the code from OnChange (occurs when the contents of a text box or the text portion of a combo box changes) work for you?

    Or perhaps from the OnCurrent event (occurs when the focus moves to a record, making it the current record, or when the form is refreshed or requeried), you could requery the form from the AfterUpdate or OnChange event of the text box?

    Code:
    If IsNull (form!thefield) Then
    'Do nothing
    Else
    'run your code here
    End If
    Hope this helps,

    Dave.

    _____________

    Access 2000 User

  3. #3
    Join Date
    May 2009
    Posts
    2

    That worked--thanks!!

    I am grateful for your suggestion of using the On Change event instead of the On Dirty event. This resolved the issue. I am also grateful for your explanation of why the prior would not work. Many thanks!

  4. #4
    Join Date
    Jan 2012
    Posts
    97
    Your welcome.
    Hope this helps,

    Dave.

    _____________

    Access 2000 User

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •