Results 1 to 3 of 3
  1. #1
    Join Date
    May 2014
    Posts
    98

    Unanswered: Enable disable function not working

    I have 3 values in a combo box with value1-ID 1, Value2 ID 2 and Value3-ID3 and I have another 3 combo boxes A, B, C. what I am trying to do is if value2 is selected then disable combo boxes A and if value 3 is selected then disable combo box B and C and I am using this code


    Private Sub EnableDisable1(Argument As Boolean)

    Me.Prepare1.Enabled = Argument


    End Sub
    Private Sub EnableDisable(Argument As Boolean)

    Me.Prepare2.Enabled = Argument
    Me.Present2.Enabled = Argument

    End Sub
    Private Sub Reason_AfterUpdate()

    If Me.Reason = 1 Then
    EnableDisable (True)

    Exit Sub
    End If

    EnableDisable (False)
    Exit Sub

    If Me.Reason = 2 Then
    EnableDisable1 (False)

    Exit Sub
    End If

    EnableDisable1 (True)
    Exit Sub

    If Me.Reason = 3 Then

    EnableDisable (False)

    Exit Sub
    End If
    '

    EnableDisable (True)

    Exit Sub

    End Sub
    Private Sub Reason_AfterUpdate()
    If Me.Reason = 2 Then
    Prepare1.Enabled = False
    End If


    If Me.Reason = 3 Then
    Prepare1.Enabled = False
    Present1.Enabled = False
    End If
    End Sub
    but what's happening is if I select value 2 value 3 selection function doesn't work and vice versa. Meaning If value2 selected combo box A will be disabled however when I choose value3 then combobox A and B doesn't work as required

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Doesn't work isn't ever an acceptable error condition when requesting help on forums...

    So you want to control whether something is enabled or not depending on the value in another control.

    So there are several issues
    it needs to change when the value if the control changes
    it needs to change when you display a new row.

    So for me write a function which accepts a value. Based on that value set whatever states you need
    call that function in
    the forms on current event
    the controls on change or on lost focus event
    You need to decide how you handle a change in value which would cause pre-existing data to be lost.

    Say combo box a has a value, user selects value 3 meaning combo box a should no longer have a value....

    But just talking about this design makes me suspicious that you are trying to coerce an non normalized design.
    Last edited by Missinglinq; 02-26-15 at 22:51.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Mar 2015
    Posts
    27

    Premature exit from your reason processing sub....

    In your provided code sample, the reason it never properly processes anything beyond your first check is that you never get to the code that handles the others. You exit the sub unconditionally after reason = 1 processing. You also have two different copies of Sub Reason_AfterUpdate().
    Code:
    Private Sub EnableDisable1(Argument As Boolean)
        Me.Prepare1.Enabled = Argument
    End Sub
    
     
    Private Sub EnableDisable(Argument As Boolean)
        Me.Prepare2.Enabled = Argument
        Me.Present2.Enabled = Argument
    End Sub
     
    
    Private Sub Reason_AfterUpdate()
        If Me.Reason = 1 Then
            EnableDisable (True)
            Exit Sub
        End If
    
        EnableDisable (False)
        Exit Sub  ' <--- you will never make it past here!
    
        If Me.Reason = 2 Then
            EnableDisable1 (False)
            Exit Sub
        End If
    
        EnableDisable1 (True)
        Exit Sub  ' <--- or here
    
        If Me.Reason = 3 Then
            EnableDisable (False)
            Exit Sub
        End If
     
        EnableDisable (True)
        Exit Sub
    
    End Sub
    
    
    Private Sub Reason_AfterUpdate()
        If Me.Reason = 2 Then
            Prepare1.Enabled = False
        End If
    
        If Me.Reason = 3 Then
            Prepare1.Enabled = False
            Present1.Enabled = False
        End If
    End Sub
    Last edited by rodrich1954; 03-25-15 at 12:08.

Posting Permissions

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