61044

Check to see if 8 comboboxes contain values that match one another excluding null

Question:

How do I check to see if any of my 8 comboboxes match one another all at once (excluding null values of course, because they are all null when the form loads)? At the moment I have only figured out how to do it for the current and next one. In the case where there is a match, I want to clear the values of all the other comboboxes apart from the one in focus i.e. currentDropDown.

Code below:

Private Sub Form_Load() cboOption2.Enabled = False cboOption3.Enabled = False cboOption4.Enabled = False cboOption6.Enabled = False cboOption7.Enabled = False cboOption8.Enabled = False cboOption1.Value = Null cboOption2.Value = Null cboOption3.Value = Null cboOption4.Value = Null cboOption5.Value = Null cboOption6.Value = Null cboOption7.Value = Null cboOption8.Value = Null End Sub Sub rTotal(currentDropDown, nextDropDown) If (currentDropDown.Value = nextDropDown.Value) Then MsgBox "You cannot select the same value twice." currentDropDown.Value = Null End If End Sub Private Sub cboOption1_Change() Call rTotal(cboOption1, cboOption2) End Sub Private Sub cboOption2_Change() Call rTotal(cboOption2, cboOption3) End Sub Private Sub cboOption3_Change() Call rTotal(cboOption3, cboOption4) End Sub Private Sub cboOption4_Change() Call rTotal(cboOption4, cboOption5) End Sub Private Sub cboOption5_Change() Call rTotal(cboOption5, cboOption6) End Sub Private Sub cboOption6_Change() Call rTotal(cboOption6, cboOption7) End Sub Private Sub cboOption7_Change() Call rTotal(cboOption7, cboOption8) End Sub Private Sub cboOption8_Change() Call rTotal(cboOption8, cboOption8) End Sub

Answer1:

You need to loop through the collection of comboboxes and check currently selected value to the others.

Sub CheckValue(ByVal currCombobox As ComboBox) Dim ctl As Control, cmb As ComboBox For Each ctl In Me.Controls If ctl.ControlType = acComboBox Then Set cmb = ctl If (currCombobox.Value = cmb.Value) And (Not currCombobox Is cmb) Then MsgBox "Cannot select it twice!" & vbcr & vbcr & _ currCombobox.Name & " = " & cmb.Name End If End If Next ctl Set ctl = Nothing End Sub

usage:

Private Sub CombBox30_Change() CheckValue CombBox30 End Sub

Recommend

  • Session Data lost after redirect in CodeIgniter 3.1.2
  • Assigning fixed drive letters to USB Devices on Windows Server (2012)
  • Calling a function on grid action coumn click
  • Firebase Analytics not working with Instant App or Normal App
  • Displaying comments for all post
  • How to display info if a tag value is X
  • LESS: Inheritance using a variable
  • What is the right c++ variant syntax for calling a member function set to a particular variant?
  • C# ItextSharp Fontawesome Icons ( currency ) - PDF
  • Manipulate FontAwesome with Javascript
  • images are uploaded but I can't see them
  • C# ItextSharp Fontawesome Icons ( currency ) - PDF
  • What is the right c++ variant syntax for calling a member function set to a particular variant?
  • Template Factory Pattern in C++
  • What is #shadow-root, and why does it put display none on my font awesome classes? [duplicate]
  • Link to specific tab Bootstrap Codeigniter
  • Datatables child row with PHP data from Codeigniter
  • Display old and new values for a cell
  • Integrating FontAwesome into KendoUI CSS
  • XSLT-1.0 How to pick multiple tags between two similar tags as it is?
  • Firebase/Angular: Messages not showing in HTML, but contain the message objects
  • AngularFire & Ionic - No data form is transmitted to server
  • Matching line width in legend to line width in plot using ggplot2
  • How to set “activate” class to bootstrap navbar in Angular 2 while using page anchor navigation?
  • MVC5 Ajax.BeginForm upload form with files
  • How to find the Custom Field detail of a product backlog item TFS by WIQL
  • “^” in regex pattern make an error
  • Sonata Admin Bundle custom group icon
  • How can I compose a VM into a view within an Aurelia validation renderer
  • Toggle DIV state localstorage
  • Javascript onclick does not fire when developer tools are open
  • Create unique ids for a group
  • Finding regular expressions for languages otherwise described
  • JSON Error when parsing “… has no method 'replace'”
  • Cant find why the layout is getting smaller
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs