Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Run-time error 3464" - Data type mismatch in criteria expression
    primarykey
    data
    text
    <p>[Below I am setting the parameters in vba to send to an access query. The query takes a Start Date, End Date, Reason Code and Sub Group. All the criterion are String except for Sub Group which is an integer. </p> <pre><code>Sub FinalDrill() 'Step 1: Declare your variables Dim DatabasePath As String DatabasePath = ThisWorkbook.Path &amp; "\SpreadSheetData.accdb" Dim MyDatabase As DAO.Database Dim MyQueryDef As DAO.QueryDef Dim MyRecordset As DAO.Recordset Dim i As Integer 'Step 2: Identify the database and query Set MyDatabase = DBEngine.OpenDatabase _ (DatabasePath) Set MyQueryDef = MyDatabase.QueryDefs("FinalDrill") 'Step 3: Define the Parameters With MyQueryDef .Parameters("[Start Date]") = GetStartDate() .Parameters("[End Date]") = GetEndDate() .Parameters("[Reason Code]") = "C" .Parameters("[Sub Group]") = 2 End With 'Step 4: Open the query Set MyRecordset = MyQueryDef.OpenRecordset </code></pre> <p>The final line throws "Run-time error 3464" - Data type mismatch in criteria expression</p> <p>I don't get it because i have run this exact type of query from different subs with just the Start Date and End Date and it works a treat.... even is i comment out the</p> <pre><code>'.Parameters("[Reason Code]") = "C" '.Parameters("[Sub Group]") = 2 </code></pre> <p>and change the access query to only except the Start Date and End Date I get the same error. </p> <p>Maybe I'm tired and missing something obvious, any help would be great.</p> <p><strong>UPDATE</strong></p> <p>The below query works so I'm guessing the problem is in my access query.</p> <pre><code>'Step 1: Declare your variables Dim DatabasePath As String DatabasePath = ThisWorkbook.Path &amp; "\SpreadSheetData.accdb" Dim MyDatabase As DAO.Database Dim MyQueryDef As DAO.QueryDef Dim MyRecordset As DAO.Recordset Dim i As Integer 'Step 2: Identify the database and query Set MyDatabase = DBEngine.OpenDatabase _ (DatabasePath) Set MyQueryDef = MyDatabase.QueryDefs("levelOnePie") 'Step 3: Define the Parameters With MyQueryDef .Parameters("[Start Date]") = GetStartDate() .Parameters("[End Date]") = GetEndDate() End With 'Step 4: Open the query Set MyRecordset = MyQueryDef.OpenRecordset </code></pre> <p>Will update with more results once i find them.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload