Results 1 to 2 of 2
  1. #1
    Philosophaie is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    28

    Data type mismatch in criteria expression error from Excel

    I am trying to populate a Access table from Excel 2010.



    I get the error: "Data type mismatch in criteria expression."

    It points to the rs.Open command.

    I tried a few different ways but each time the same error occurs.

    Code:
        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim ConnStr As String
        Set rs = New ADODB.Recordset
        Set cn = New ADODB.Connection
        ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\path\db1.mdb;"
        cn.Open (ConnStr)
        For k = 1 To Sheets("2013").Cells(Rows.Count, "A").End(xlUp).Row - 4
            With rs
                PrimaryKey = k
                SQLstr = "SELECT * FROM [table1] WHERE [Index]='" & PrimaryKey & "';"
    
                .Open Source:=SQLstr, ActiveConnection:=cn, CursorType:=adOpenDynamic, LockType:=adLockOptimistic, Options:=adCmdText
                
                If .EOF = True Then
                  .AddNew ' create a new record
                End If
                .Fields("Index") = Sheets("2013").Cells(k + 4, 1).Value
                .Fields("DatePaid") = Sheets("2013").Cells(k + 4, 2).Value
                .Fields("WhatPaid") = Sheets("2013").Cells(k + 4, 3).Value
                .Fields("AmtPaid") = Sheets("2013").Cells(k + 4, 4).Value
                .Fields("Total") = Sheets("2013").Cells(k + 4, 5).Value
                .Fields("AmtRec") = Sheets("2013").Cells(k + 4, 6).Value
                .Fields("WhatRec") = Sheets("2013").Cells(k + 4, 7).Value
                .Fields("DateRec") = Sheets("2013").Cells(k + 4, 8).Value
                .Update
            End With
        Next k
        rs.Close
        Set rs = Nothing
        cn.Close
        Set cn = Nothing

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is Index a number type field? If so, remove the apostrophe delimiters from around PrimaryKey variable. Numbers don't require delimiters. Apostrophe is for text and # for date.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-11-2012, 10:59 AM
  2. Data type mismatch in criteria expression
    By bobt_1234 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 03:37 PM
  3. Data Type mismatch in criteria expression
    By elb1999 in forum Queries
    Replies: 2
    Last Post: 01-20-2012, 02:38 PM
  4. Replies: 2
    Last Post: 05-17-2011, 02:40 PM
  5. data type mismatch in criteria expression
    By broecher in forum Access
    Replies: 4
    Last Post: 09-10-2010, 08:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums