Access: Disable comboboxes












1














I've got 5 comboboxes in my form, and I would like the user to only be able to select 2. Once 2 is selected, the other 3 will be disabled? How'd I go about this? I know you can do one combobox and disable the rest by afterupdate as below. Appreciate your help! :)



Private Sub cboOR_AfterUpdate()
Me.cboA.Enabled = False
End Sub









share|improve this question





























    1














    I've got 5 comboboxes in my form, and I would like the user to only be able to select 2. Once 2 is selected, the other 3 will be disabled? How'd I go about this? I know you can do one combobox and disable the rest by afterupdate as below. Appreciate your help! :)



    Private Sub cboOR_AfterUpdate()
    Me.cboA.Enabled = False
    End Sub









    share|improve this question



























      1












      1








      1







      I've got 5 comboboxes in my form, and I would like the user to only be able to select 2. Once 2 is selected, the other 3 will be disabled? How'd I go about this? I know you can do one combobox and disable the rest by afterupdate as below. Appreciate your help! :)



      Private Sub cboOR_AfterUpdate()
      Me.cboA.Enabled = False
      End Sub









      share|improve this question















      I've got 5 comboboxes in my form, and I would like the user to only be able to select 2. Once 2 is selected, the other 3 will be disabled? How'd I go about this? I know you can do one combobox and disable the rest by afterupdate as below. Appreciate your help! :)



      Private Sub cboOR_AfterUpdate()
      Me.cboA.Enabled = False
      End Sub






      ms-access combobox






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 9:49









      Miles Sabin

      21.6k65293




      21.6k65293










      asked Dec 28 '18 at 9:25









      sherrysherry

      113




      113
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Check this out



          Private Sub Combo0_AfterUpdate()
          If CheckCombo Then
          disableCombo
          Else
          enableCombo
          End If
          End Sub



          Private Sub Combo10_AfterUpdate()
          If CheckCombo Then
          disableCombo
          Else
          enableCombo
          End If
          End Sub

          Private Sub Combo12_AfterUpdate()
          If CheckCombo Then
          disableCombo
          Else
          enableCombo
          End If
          End Sub

          Private Sub Combo14_AfterUpdate()
          If CheckCombo Then
          disableCombo
          Else
          enableCombo
          End If
          End Sub

          Private Sub Combo16_AfterUpdate()
          If CheckCombo Then
          disableCombo
          Else
          enableCombo
          End If
          End Sub


          Private Function CheckCombo() As Boolean

          Dim retVal As Long
          retVal = IIf(Len(Nz(Combo0, "")) > 0, 1, 0) + IIf(Len(Nz(Combo10, "")) > 0, 1, 0) + IIf(Len(Nz(Combo12, "")) > 0, 1, 0) + IIf(Len(Nz(Combo14, "")) > 0, 1, 0) + IIf(Len(Nz(Combo16, "")) > 0, 1, 0)
          CheckCombo = (retVal >= 2)

          End Function

          Private Sub enableCombo()
          Combo0.Enabled = True
          Combo10.Enabled = True
          Combo12.Enabled = True
          Combo14.Enabled = True
          Combo16.Enabled = True
          End Sub

          Private Sub disableCombo()
          If Len(Nz(Combo0, "")) <= 0 Then Combo0.Enabled = False
          If Len(Nz(Combo10, "")) <= 0 Then Combo10.Enabled = False
          If Len(Nz(Combo12, "")) <= 0 Then Combo12.Enabled = False
          If Len(Nz(Combo14, "")) <= 0 Then Combo14.Enabled = False
          If Len(Nz(Combo16, "")) <= 0 Then Combo16.Enabled = False
          End Sub





          share|improve this answer





















          • Thanks a lot!! this did the trick :D!
            – sherry
            Dec 31 '18 at 1:54



















          0














          Put this Sub in form's module



          Private Sub changeStateOfCB()

          Dim nameChB() As String
          Dim cMax As Long
          Dim ctrl As Control
          Dim cValued As Long
          Dim nameCurr As Variant

          ' names of CB
          nameChB = Split("ComboName1#ComboName2#ComboName3#ComboName4#ComboName5", "#")
          ' max allowed values
          cMax = 2

          ' counting with values
          For Each nameCurr In nameChB
          If Not Me.Controls(nameCurr).Value Is Null Then
          cValued = cValued + 1
          End If
          Next
          ' disabling if needed
          For Each nameCurr In nameChB
          If Not Me.Controls(nameCurr).Value Is Null Then
          Me.Controls(nameCurr).Enabled = (cValued < cMax)
          End If
          Next

          End Sub


          Change names in string according to you names in nameChB line.
          And for every combo box create AfterUpdate event procedures with call



          changeStateOfCB





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53956257%2faccess-disable-comboboxes%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Check this out



            Private Sub Combo0_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub



            Private Sub Combo10_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo12_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo14_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo16_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub


            Private Function CheckCombo() As Boolean

            Dim retVal As Long
            retVal = IIf(Len(Nz(Combo0, "")) > 0, 1, 0) + IIf(Len(Nz(Combo10, "")) > 0, 1, 0) + IIf(Len(Nz(Combo12, "")) > 0, 1, 0) + IIf(Len(Nz(Combo14, "")) > 0, 1, 0) + IIf(Len(Nz(Combo16, "")) > 0, 1, 0)
            CheckCombo = (retVal >= 2)

            End Function

            Private Sub enableCombo()
            Combo0.Enabled = True
            Combo10.Enabled = True
            Combo12.Enabled = True
            Combo14.Enabled = True
            Combo16.Enabled = True
            End Sub

            Private Sub disableCombo()
            If Len(Nz(Combo0, "")) <= 0 Then Combo0.Enabled = False
            If Len(Nz(Combo10, "")) <= 0 Then Combo10.Enabled = False
            If Len(Nz(Combo12, "")) <= 0 Then Combo12.Enabled = False
            If Len(Nz(Combo14, "")) <= 0 Then Combo14.Enabled = False
            If Len(Nz(Combo16, "")) <= 0 Then Combo16.Enabled = False
            End Sub





            share|improve this answer





















            • Thanks a lot!! this did the trick :D!
              – sherry
              Dec 31 '18 at 1:54
















            0














            Check this out



            Private Sub Combo0_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub



            Private Sub Combo10_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo12_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo14_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo16_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub


            Private Function CheckCombo() As Boolean

            Dim retVal As Long
            retVal = IIf(Len(Nz(Combo0, "")) > 0, 1, 0) + IIf(Len(Nz(Combo10, "")) > 0, 1, 0) + IIf(Len(Nz(Combo12, "")) > 0, 1, 0) + IIf(Len(Nz(Combo14, "")) > 0, 1, 0) + IIf(Len(Nz(Combo16, "")) > 0, 1, 0)
            CheckCombo = (retVal >= 2)

            End Function

            Private Sub enableCombo()
            Combo0.Enabled = True
            Combo10.Enabled = True
            Combo12.Enabled = True
            Combo14.Enabled = True
            Combo16.Enabled = True
            End Sub

            Private Sub disableCombo()
            If Len(Nz(Combo0, "")) <= 0 Then Combo0.Enabled = False
            If Len(Nz(Combo10, "")) <= 0 Then Combo10.Enabled = False
            If Len(Nz(Combo12, "")) <= 0 Then Combo12.Enabled = False
            If Len(Nz(Combo14, "")) <= 0 Then Combo14.Enabled = False
            If Len(Nz(Combo16, "")) <= 0 Then Combo16.Enabled = False
            End Sub





            share|improve this answer





















            • Thanks a lot!! this did the trick :D!
              – sherry
              Dec 31 '18 at 1:54














            0












            0








            0






            Check this out



            Private Sub Combo0_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub



            Private Sub Combo10_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo12_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo14_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo16_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub


            Private Function CheckCombo() As Boolean

            Dim retVal As Long
            retVal = IIf(Len(Nz(Combo0, "")) > 0, 1, 0) + IIf(Len(Nz(Combo10, "")) > 0, 1, 0) + IIf(Len(Nz(Combo12, "")) > 0, 1, 0) + IIf(Len(Nz(Combo14, "")) > 0, 1, 0) + IIf(Len(Nz(Combo16, "")) > 0, 1, 0)
            CheckCombo = (retVal >= 2)

            End Function

            Private Sub enableCombo()
            Combo0.Enabled = True
            Combo10.Enabled = True
            Combo12.Enabled = True
            Combo14.Enabled = True
            Combo16.Enabled = True
            End Sub

            Private Sub disableCombo()
            If Len(Nz(Combo0, "")) <= 0 Then Combo0.Enabled = False
            If Len(Nz(Combo10, "")) <= 0 Then Combo10.Enabled = False
            If Len(Nz(Combo12, "")) <= 0 Then Combo12.Enabled = False
            If Len(Nz(Combo14, "")) <= 0 Then Combo14.Enabled = False
            If Len(Nz(Combo16, "")) <= 0 Then Combo16.Enabled = False
            End Sub





            share|improve this answer












            Check this out



            Private Sub Combo0_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub



            Private Sub Combo10_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo12_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo14_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub

            Private Sub Combo16_AfterUpdate()
            If CheckCombo Then
            disableCombo
            Else
            enableCombo
            End If
            End Sub


            Private Function CheckCombo() As Boolean

            Dim retVal As Long
            retVal = IIf(Len(Nz(Combo0, "")) > 0, 1, 0) + IIf(Len(Nz(Combo10, "")) > 0, 1, 0) + IIf(Len(Nz(Combo12, "")) > 0, 1, 0) + IIf(Len(Nz(Combo14, "")) > 0, 1, 0) + IIf(Len(Nz(Combo16, "")) > 0, 1, 0)
            CheckCombo = (retVal >= 2)

            End Function

            Private Sub enableCombo()
            Combo0.Enabled = True
            Combo10.Enabled = True
            Combo12.Enabled = True
            Combo14.Enabled = True
            Combo16.Enabled = True
            End Sub

            Private Sub disableCombo()
            If Len(Nz(Combo0, "")) <= 0 Then Combo0.Enabled = False
            If Len(Nz(Combo10, "")) <= 0 Then Combo10.Enabled = False
            If Len(Nz(Combo12, "")) <= 0 Then Combo12.Enabled = False
            If Len(Nz(Combo14, "")) <= 0 Then Combo14.Enabled = False
            If Len(Nz(Combo16, "")) <= 0 Then Combo16.Enabled = False
            End Sub






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 28 '18 at 10:35









            SantoshSantosh

            10.1k22858




            10.1k22858












            • Thanks a lot!! this did the trick :D!
              – sherry
              Dec 31 '18 at 1:54


















            • Thanks a lot!! this did the trick :D!
              – sherry
              Dec 31 '18 at 1:54
















            Thanks a lot!! this did the trick :D!
            – sherry
            Dec 31 '18 at 1:54




            Thanks a lot!! this did the trick :D!
            – sherry
            Dec 31 '18 at 1:54













            0














            Put this Sub in form's module



            Private Sub changeStateOfCB()

            Dim nameChB() As String
            Dim cMax As Long
            Dim ctrl As Control
            Dim cValued As Long
            Dim nameCurr As Variant

            ' names of CB
            nameChB = Split("ComboName1#ComboName2#ComboName3#ComboName4#ComboName5", "#")
            ' max allowed values
            cMax = 2

            ' counting with values
            For Each nameCurr In nameChB
            If Not Me.Controls(nameCurr).Value Is Null Then
            cValued = cValued + 1
            End If
            Next
            ' disabling if needed
            For Each nameCurr In nameChB
            If Not Me.Controls(nameCurr).Value Is Null Then
            Me.Controls(nameCurr).Enabled = (cValued < cMax)
            End If
            Next

            End Sub


            Change names in string according to you names in nameChB line.
            And for every combo box create AfterUpdate event procedures with call



            changeStateOfCB





            share|improve this answer




























              0














              Put this Sub in form's module



              Private Sub changeStateOfCB()

              Dim nameChB() As String
              Dim cMax As Long
              Dim ctrl As Control
              Dim cValued As Long
              Dim nameCurr As Variant

              ' names of CB
              nameChB = Split("ComboName1#ComboName2#ComboName3#ComboName4#ComboName5", "#")
              ' max allowed values
              cMax = 2

              ' counting with values
              For Each nameCurr In nameChB
              If Not Me.Controls(nameCurr).Value Is Null Then
              cValued = cValued + 1
              End If
              Next
              ' disabling if needed
              For Each nameCurr In nameChB
              If Not Me.Controls(nameCurr).Value Is Null Then
              Me.Controls(nameCurr).Enabled = (cValued < cMax)
              End If
              Next

              End Sub


              Change names in string according to you names in nameChB line.
              And for every combo box create AfterUpdate event procedures with call



              changeStateOfCB





              share|improve this answer


























                0












                0








                0






                Put this Sub in form's module



                Private Sub changeStateOfCB()

                Dim nameChB() As String
                Dim cMax As Long
                Dim ctrl As Control
                Dim cValued As Long
                Dim nameCurr As Variant

                ' names of CB
                nameChB = Split("ComboName1#ComboName2#ComboName3#ComboName4#ComboName5", "#")
                ' max allowed values
                cMax = 2

                ' counting with values
                For Each nameCurr In nameChB
                If Not Me.Controls(nameCurr).Value Is Null Then
                cValued = cValued + 1
                End If
                Next
                ' disabling if needed
                For Each nameCurr In nameChB
                If Not Me.Controls(nameCurr).Value Is Null Then
                Me.Controls(nameCurr).Enabled = (cValued < cMax)
                End If
                Next

                End Sub


                Change names in string according to you names in nameChB line.
                And for every combo box create AfterUpdate event procedures with call



                changeStateOfCB





                share|improve this answer














                Put this Sub in form's module



                Private Sub changeStateOfCB()

                Dim nameChB() As String
                Dim cMax As Long
                Dim ctrl As Control
                Dim cValued As Long
                Dim nameCurr As Variant

                ' names of CB
                nameChB = Split("ComboName1#ComboName2#ComboName3#ComboName4#ComboName5", "#")
                ' max allowed values
                cMax = 2

                ' counting with values
                For Each nameCurr In nameChB
                If Not Me.Controls(nameCurr).Value Is Null Then
                cValued = cValued + 1
                End If
                Next
                ' disabling if needed
                For Each nameCurr In nameChB
                If Not Me.Controls(nameCurr).Value Is Null Then
                Me.Controls(nameCurr).Enabled = (cValued < cMax)
                End If
                Next

                End Sub


                Change names in string according to you names in nameChB line.
                And for every combo box create AfterUpdate event procedures with call



                changeStateOfCB






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 28 '18 at 10:28

























                answered Dec 28 '18 at 10:15









                4dmonster4dmonster

                2,43111020




                2,43111020






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53956257%2faccess-disable-comboboxes%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas