Type Mismatch Error

Type Mismatch Error

I have an SQL statement in my program that looks like this:

data3.recordsource = “SELECT id, date from reservations where (date = ‘” & maskededit1.text & “‘) and (id = ” & data1.recordset.fields(“movie_id”).value & “)”
“date” is declared as Date/Time, “id” and “movie_id” are integers. The program crashes on this statement (which is on the line after the SELECT statement):
It gives me a “Type Mismatch” error. I have spent two days trying to solve this problem.

Try the following to replace your code:

Dim sSQL as StringsSQL = “SELECT id, date FROM reservations WHERE “sSQL = sSQL + “date = ” + CVar(MaskedEdit1.Text)sSQL = sSQL + ” AND id = ” + data1.recordset(“movie_id”)data3.RecordSource = sSQLdata3.Refresh
This broke the SQL statement up to make it more readable. CVar converts text to a Variant, which deals with dates much better. In addition, no parentheses are needed in the SELECT statement. Also, to get the field value, you do not use the Fields collection. The Recordset property is a Dynaset, and can be used as such.

See also  How HealthStream Learning Center Supports Healthcare Education and Compliance

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist