Results 1 to 6 of 6
  1. #1
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128

    Enable disable function not working


    I have 3 values in a combo box with value1-ID1, Value2-ID2 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

    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
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Note that I edited your post to include CODE tags so code is more readable.

    The Reason_AfterUpdate procedure should never get beyond that second Exit Sub. Why do you have those 3 Exit Sub lines outside any conditional structure?

    Probably should use Conditional Formatting instead of VBA code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    JeffChr is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    82
    based on your explanation and code I am having a difficult time figuring out your problem. but I did notice that your Private Sub Reason_AfterUpdate() procedure will never get past a certain point:

    Private Sub Reason_AfterUpdate()
    If Me.reason = 1 Then
    EnableDisable (True)
    Exit Sub
    End If
    EnableDisable (False)
    Exit Sub -------------------------------------------------if the routine wasn't exited 3 steps above, it will exit here in all situations
    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


  4. #4
    reentry is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    9
    If i got u right this code should work for u. Isnt the nicest code but the easiest in my opinion.

    Code:
    Private Sub Reason_AfterUpdate()    
    Select Case Me.reason
        Case 1
            Me.Prepare1.Enabled = True
            Me.Prepare2.Enabled = True
            Me.Present2.Enabled = True
        Case 2
            Me.Prepare1.Enabled = False
            Me.Prepare2.Enabled = True
            Me.Present2.Enabled = True
        Case 3
            Me.Prepare1.Enabled = True
            Me.Prepare2.Enabled = False
            Me.Present2.Enabled = False
        End Select
    End Sub

  5. #5
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Perfect

    This worked perfectly reentry. Thanks

  6. #6
    reentry is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    9
    You're welcome. But pls mark the threat as solved

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

Similar Threads

  1. Password Form With Enable/Disable Shift Key
    By burrina in forum Code Repository
    Replies: 0
    Last Post: 12-24-2012, 10:53 PM
  2. Replies: 2
    Last Post: 11-30-2012, 08:03 PM
  3. Enable/Disable Button
    By P.Malius in forum Programming
    Replies: 3
    Last Post: 09-07-2012, 08:36 AM
  4. Enable or Disable Field in Forum
    By lolos66666 in forum Forms
    Replies: 5
    Last Post: 03-13-2011, 05:30 PM
  5. Function to Enable/Disable Field
    By swalsh84 in forum Programming
    Replies: 5
    Last Post: 11-04-2010, 02:48 PM

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