Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Posts
    2

    Unanswered: open recordset error

    I get a 'data type mismatch in criteria expression' when trying to open a recordset from a query that uses a variable in the match. It works fine if I use the query without the varible. The error occurs at the rs1.open line, not the sqlstmt line.

    ticket=1002
    db_file = App.Path & "\goldpos.mdb"

    Set cn = New ADODB.Connection
    cn.CursorLocation = adUseClient
    cn.ConnectionString = _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & db_file & ";" & _
    "Persist Security Info=False"
    cn.Open

    'sqlstmt = "SELECT * FROM orders where [invoice] = 1002" THIS WORKS
    sqlstmt = "SELECT * FROM orders where [invoice] = '" & ticket & "'" 'THIS DOESN'T WORK

    Set rs1 = New ADODB.Recordset

    rs1.Open sqlstmt, cn, adOpenStatic, adLockOptimistic, adCmdText

    Set DataGrid1.DataSource = rs1

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: open recordset error

    Originally posted by JerryB
    'sqlstmt = "SELECT * FROM orders where [invoice] = 1002" THIS WORKS
    sqlstmt = "SELECT * FROM orders where [invoice] = '" & ticket & "'" 'THIS DOESN'T WORK
    Why are you adding single quotes around ticket if it just wants a number? Why not:

    sqlstmt = "SELECT * FROM orders where [invoice] = " & ticket

Posting Permissions

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