Consulting

Results 1 to 2 of 2

Thread: datatype mismatch in criteria expression

  1. #1

    datatype mismatch in criteria expression

    This error is driving me nuts, not quite sure how to tackle it. Basically I have a tool which queries 2 worksheets in a workbook, but whenever I try to run it I get the datatype mismatch error. Here is the troublesome block of code:

    [VBA]objRec.Open "(SELECT [Scheduled Date] FROM [Individual Site Scheduling$] " & _
    "WHERE (MID([REMOTE ID],1,4) = """ & SiteData.[RemoteID].Range("A" & curRow) & """ AND " & _
    "FORMAT([In Service], 'YYYYMMDD') = """ & Format(SiteData.[InService].Range("A" & curRow), "YYYYMMDD") & """ AND " & _
    "[DSA] = " & SiteData.[DSA].Range("A" & curRow) & ")) UNION " & _
    "(SELECT [Scheduled Date] FROM [Completed Sites$] " & _
    "WHERE (MID([REMOTE ID],1,4) = """ & SiteData.[RemoteID].Range("A" & curRow) & """ AND " & _
    "FORMAT([In Service], 'YYYYMMDD') = """ & Format(SiteData.[InService].Range("A" & curRow), "YYYYMMDD") & """ AND " & _
    "[DSA] = " & SiteData.[DSA].Range("A" & curRow) & "))", _
    objCon, adOpenStatic, adLockReadOnly[/VBA]

    Any ideas? I've googled the error and it seems it may have something to do with my quotation marks, but so far nothing has worked.
    Phil J.

  2. #2
    Textual data types in SQL strings must be surrounded by an apostrophe as far as I know:

    Select * From Cities Where City = 'Amsterdam'

    Can you perhaps post the exact SQL string that is being passed to the Open method, rather than the code?
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •