Type mismatch error

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.
 
G

Geof Wyght

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.
 
V

Van T. Dinh

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
 
H

Hana

Dear Van.

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

Thank you very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top