CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Posts
    22

    openrecordset,sql expression

    Why am I getting a run time error 3464?
    Data Type mismatch in criteria expression

    I am running a test query on an access database with the following code:
    Static pubidno As Integer
    Static stateno As String

    pubidno = 100
    stateno = "NY"

    Dim dbs As Database, rst As Recordset
    Set dbs = OpenDatabase("c:\program files\devstudio\vb\db1.mdb")
    Set rst = dbs.OpenRecordset("SELECT * FROM Publishers " _
    & "WHERE PubID < '" & pubidno & "' " _
    & "AND State = '" & stateno & "' " _
    & "ORDER BY Name ")
    Set rst = Data1.Recordset
    rst.Close



  2. #2
    Join Date
    Apr 1999
    Location
    Brooklyn, NY USA
    Posts
    171

    Re: openrecordset,sql expression

    Delete quotes from your SQL statement: "WHERE PubID < " & pubidno & "....
    Vlad


  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: openrecordset,sql expression

    looks like your Pubid is a numeric field. So get rid of the single quotes.
    WHERE pubid < " & pubidno & " ...


  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: openrecordset,sql expression

    Oops, I just saw that you answered that question half an hour ago. I didn't see that (need to hit the refresh button more often).


  5. #5
    Join Date
    Aug 1999
    Posts
    8

    Re: openrecordset,sql expression

    Hi, here is the solution. You might have declared pubidno as integer. Hence no quotes are allowed on integer field. The is the final code:
    -------------------------------------------
    Static pubidno As Integer
    Static stateno As String

    pubidno = 100
    stateno = "NY"

    Dim dbs As Database
    Dim rst As Recordset
    Set dbs = OpenDatabase("c:\program files\devstudio\vb\biblio.mdb")
    Set rst = dbs.OpenRecordset("SELECT * FROM Publishers " _
    & "WHERE PubID < " & pubidno _
    & "AND State = '" & stateno & "' " _
    & "ORDER BY Name ")

    Debug.Print rst.Fields(0).Value
    Debug.Print rst.Fields(1).Value
    rst.Close
    --------------------------------------------------
    From:
    Ashok


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured