Command button disabled upon multiple conditions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hiramicus
    New Member
    • Mar 2010
    • 4

    Command button disabled upon multiple conditions

    Hi - I'm using Access 2003.

    I have an input form that I'm trying to link to multiple tables. I have a command button that updates all the tables with the ~40 textboxes which the user inputs the values.

    I'm wondering if there's a way I can make the command button disabled until the value of the text box differs from that of the input tables. The only way I can think is to have a subroutine for every text box "after update" that compares the values and changed the enabled setting; however, in lieu of writing 40 different subroutines, is there a more efficient way to do this?

    Thanks,
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    If the form is bound, you could enable the button in the form's Dirty
    Code:
    Private Sub Form_Dirty(Cancel As Integer)
      btn_Save.Enabled=True
    End Sub

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      That doesn't address the OPs question, Smiley! If this is a bound form, the Form_Dirty event will fire the second a single character is entered in the new record, whether or not the value of the current textbox "differs" from that of the "input tables." If the form is unbound (as it sounds from the description) it won't fire at all.

      I think we need a much clearer explanation of what Hiramicus is trying to do here.

      Is this form bound or unbound?

      Is it your intent that, say, TextboxA's value has to be different from the TextA value of any other record in the underlying table?

      Why are you using a single form to enter data for 40 fields in multiple tables?

      Welcome to Bytes!

      Linq ;0)>

      Comment

      • Hiramicus
        New Member
        • Mar 2010
        • 4

        #4
        Thanks for the Welcome.

        To explain what I'm doing a bit more, I'm using an unbound form, which will update ~5 different input tables. Because of nature of the data (and future queries off of this), I needed to use a form that would update different tables; some of the data comes in a 1xn matrix and some of it comes in a nxm matrix.

        I guess is there a way to have a global procedure that will apply to the form, rather than having many subroutines (that launch "after update" of specified field/textbox)?

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          I'm assuming that the command button you're referring to is a "save" button for writing the data to the various tables. I think you'll have to
          1. Leave the button enabled
          2. Place validation code in its OnClick event.
          3. Have t he code loop thru all controls and run a DCount() for each one to see if the value already exists
          4. If it does already exist, pop a message box to inform the user and exit the sub, moving back to the offending control


          This is a lot of work, but you're trying to do validation on 40 fields, in multiple tables. At least the code would be in a single location.

          Linq ;0)>

          Comment

          Working...