title: Receiving Type mismatch error in MS Access
body: <p>I tested my code with static value</p>
  <pre class="lang-vb prettyprint-override"><code>Set rs = CurrentDb.OpenRecordset(&quot;SELECT mail FROM UsersData WHERE depid = 2&quot;)
  </code></pre>
  <p>and it worked, but when I use the full statement</p>
  <pre class="lang-vb prettyprint-override"><code>Set rs = CurrentDb.OpenRecordset( _
    &quot;SELECT mail FROM UsersData WHERE depid IN (SELECT depid FROM CyclesDefinitions WHERE cycledefid = &quot; _
    &amp; Me.Combo135.Value &amp; &quot; AND rank = &quot; &amp; Me.Combo202.Value) &amp; &quot;)&quot;
  </code></pre>
  <p>it generates an error i don't know what it means</p>
  <blockquote>
  <p>(Compile Error: Type mismatch) and then nothing happens.</p>
  </blockquote>
  <p>full code below: (everything works as intended and tested, but this line)</p>
  <pre class="lang-VBA prettyprint-override"><code>Private Sub Command15_Click()
      Dim dbs As Database
      Dim qdf As QueryDef
          
      Set dbs = CurrentDb
      
      Dim StrSqls As String
      
      Dim rs As DAO.Recordset
      Set rs = CurrentDb.OpenRecordset(&quot;SELECT mail FROM UsersData WHERE depid IN (SELECT depid FROM CyclesDefinitions WHERE cycledefid = &quot; &amp; Me.Combo135.Value &amp; &quot; AND rank = &quot; &amp; Me.Combo202.Value) &amp; &quot;)&quot;
      'Set rs = CurrentDb.OpenRecordset(&quot;SELECT mail FROM UsersData WHERE depid = 2&quot;)
      Dim ToMails As String
         
      'Check is a flag on form to make sure record is not inserted more than once in Cycles Table
      If Me.Check137.Value = False Then
          DoCmd.RunCommand acCmdSaveRecord
          
          dbs.Execute &quot;INSERT INTO Cycles (scinvid, cycledefid) VALUES (&quot; &amp; Me.Combo200.Value &amp; &quot;, &quot; &amp; Me.Combo135.Value &amp; &quot;);&quot;
          dbs.Close
          Me.Check137.Value = True
          If Not (rs.EOF And rs.BOF) Then
             rs.MoveFirst 'Unnecessary in this case, but still a good habit
             Do Until rs.EOF = True
              ToMails = rs(0) &amp; &quot;;&quot; &amp; ToMails
              rs.MoveNext
              Loop
          Else
              MsgBox &quot;There are no Emails recorded for such department&quot;
          End If
          rs.Close 'Close the recordset
          Debug.Print ToMails
          Set rs = Nothing 'Clean up
          
          DoCmd.SendObject acSendNoObject, , , ToMails, , , &quot;Test Subject&quot;, &quot;Test Message&quot;, True
          
          'objRecordset.Open (&quot;SELECT depid FROM CyclesDefinitions WHERE cycledefid =&quot; &amp; Me.Combo135.Value &amp; &quot; AND cycleranktracking =&quot; &amp; Me.Combo202.Value)
                  
          'UserDepartmentID = DLookup(&quot;depid&quot;, &quot;UsersData&quot;, &quot;[username]= '&quot; &amp; fOSUserName &amp; &quot;'&quot;)
              
          DoCmd.GoToRecord , , acNewRec
          Me.Combo83.Requery
          Combo83.RowSource = &quot;SCINVSearch&quot;
      ElseIf Me.Check137.Value = True Then
          DoCmd.GoToRecord , , acNewRec
          Me.Combo83.Requery
          Combo83.RowSource = &quot;SCINVSearch&quot;
      End If
  End Sub
  </code></pre>