Type mismatch error

  • Thread starter Thread starter Hana
  • Start date Start date
H

Hana

Hi, all.

I get Type mismatch error, error #13, when I run following
record count code.

Me.TicketId in where clause is number not text. Is " &
Field Name & " expression for text not number?


Dim rs As Recordset
Dim strSQL As String

strSQL = "SELECT tbl_ticketdetail.MenuId FROM
tbl_ticketdetail WHERE ((tbl_ticketdetail.TicketId) = " &
Me.TicketId & ") "

Set rs = CurrentDb.OpenRecordset(strSQL,
dbOpenSnapshot)

If rs.RecordCount = 1 Then
MsgBox "Duplicated Menu!"
rs.Close
Exit Function
End If

rs.Close


Thank you.
 
Hana,
Perhaps someone entered text instead of a number. Are you
validating the value with, say, the IsNumeric function?
Are you making sure that the value is the right data type
with the CInt or CLong functions? A Null response or an
empty string might cause this problem.
Geof.
 
Your code needs DAO Recordset but the Dim statement might have created ADO
Recordset which is not compatible with DAO Recordset required by the
statement "Set rs = ..."

Make sure you have the Microsoft Data Access Object (DAO) Library included
in the References and disambiguate the declaration with:

Dim rs As DAO.Recordset
 
Dear Van.

"Dim rs As DAO.Recordset" fixed the problem like a magic.

Thank you very much.
 
Back
Top