title: Get values from a multi-value combo box in access vba
body: <p>I have a form that I'm using to gather information that will be inserted into a database table in Access 2016. My form has a multi-value combo box (called cmbContacts) that pulls values from a Contacts table (ID and Name). A user is able to select 0 or more contacts from the combo box. When a user clicks the submit button, the button_click event triggers VBA code to format the information and insert it into the table.</p>
  
  <p>What I need to do is get the IDs of each selected contact from the combo box.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>If Me.cmbContacts.ItemsSelected.Count &gt; 0 Then 'Only run code if there are contacts selected'
      'Select the most recently added entry (added right before this if statement)'
      Dim rs As DAO.Recordset, Max As Integer
      SQL = "SELECT MAX(ID) FROM Breweries"
      Set rs = CurrentDb.OpenRecordset(SQL)
      Max = rs.Fields(0)
      'Insert each selected Contact ID into Breweries.[Contact Names].Value'
      Dim itm As Variant
      For Each itm In Me.cmbContacts.ItemsSelected
          SQL = "INSERT INTO Breweries ([Contact Names].[Value]) VALUES (" + itm + ") WHERE ID=" + Max
          CurrentDb.Execute (SQL)
      Next itm
  End If
  </code></pre>
  
  <p>Some issues:</p>
  
  <ul>
  <li>Me.cmbContacts.ItemsSelected.Count always equals 0, regardless of how many items are selected in the Combo Box</li>
  <li>Because cmbContacts.ItemsSelected doesn't contain the selected items, the for loop doesn't run. I'm not sure why it's not registering the selected items</li>
  </ul>