title: Run Time Error 3464: Data Type Mismatch in criteria expression
body: <p>I have a form in Access 2010 with Two text boxes(AIPIDTxt to enter the search criteria and AIPResultTxt to display results) and a Button(Search button). I also have a Table Table1 in Access. When I click the Search Button, I need to execute a query whose criteria is in AIPIDTxt Textbox in the form, store the result in a recordset and display the results in the textbox AIPResultTxt. So I typed in the following VBA Code in the Button Event handler.</p>
  
  <pre><code>Private Sub SearchB_Click()
  
  Dim localConnection As ADODB.Connection
  Dim query As String
  Dim aipid_rs As ADODB.Recordset
  Dim db As Database
  
  Set db = CurrentDb
  Set localConnection = CurrentProject.AccessConnection
  MsgBox "Local Connection successful"
  query = "SELECT [AIP Name] FROM [Table1] WHERE [AIP ID]= 
  " &amp; [Forms]![AIPIDSearchF]![AIPIDTxt] &amp; ""
  Set aipid_rs = db.OpenRecordset(query)
  Me.AIPResultTxt.Text = aipid_rs![AIP Name]
  End Sub
  </code></pre>
  
  <p>But when I click the button I get Local Connection Successful Message Box and then a Run Time Error 3464 in the line:</p>
  
  <pre><code>Set aipid_rs= db.OpenRecordset(query)
  </code></pre>
  
  <p>I have searched for similar errors and made corrections. But the error keeps coming. Is there something wrong with my query? Couldn't figure out the error. The table is a local table. So I can directly give [Table1] and field names in the query in vba. Tried adding delimiters because the fields are text fields. But that didn't work as well. I could not give the following query as well:</p>
  
  <pre><code>query = "SELECT [AIP Name] FROM [Table1] WHERE [AIP ID]= " &amp; [Forms]![AIPIDSearchF]!
  [AIPIDTxt].Text &amp; ""
  </code></pre>
  
  <p>This gave me a run time error stating text cannot be referenced from controls that have lost focus. My criteria is text in the text box. The text box loses focus when i click the button. But when I googled for the error, solutions were to remove ".Text". So, I ended up with the above query. Do not know what is wrong with the line:</p>
  
  <pre><code>Set aipid_rs= db.OpenRecordset(query)
  </code></pre>