Question:
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):
data3.refreshIt gives me a “Type Mismatch” error. I have spent two days trying to solve this problem.
Answer:
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.RefreshThis 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.
Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.























