Type Mismatch

KRRC

Registered User.
Local time
Today, 12:30
Joined
Nov 22, 2004
Messages
12
I’m trying to get this code to work, but I’ get “Type Mismatch” on the strFilterCriteria line.
C_CG_Prod is the name of my query, and Data the name of a field in the query.

Dim db As Database
Dim strFilterCriteria As Date
strFilterCriteria = "SELECT * FROM C_CG_Prod WHERE Data = #" & InputBox "Which day:") & "# "
Set rs = db.OpenRecordset(strFilterCriteria, dbOpenDynaset)

I’d really appreciate some help.

Kathrin
 
Kathrin,

strFilterCriteria = "SELECT * FROM C_CG_Prod WHERE Data = #" & InputBox ("Which day:") & "#;"

Wayne
 
Thanks Wayne, but the problem persists....any other idea?

Kathrin
 
Open a module, go to Tools -> References and select Microsoft DAO 3.x Library. Move it above the Microsoft ActiveX 2.x Library
 
You have declared strFilterCriteria As Date, but you are assigning it a string value. This is causing the Type Mismatch.
There are other errors. You are attempting to open a recordset on db As Database, but it has not been assigned a value. You have not declared the recordset rs.
 
Well, I didn't put all my code, because I think my problem is the "Type Mismatch".
Could you please tell me how to assign a date value to the filtercriteria?

Kathrin
 
The type mismatch will be gone if you make the change indicated in bold text.
Code:
Dim db As Database
Dim strFilterCriteria As [B]String[/B]
strFilterCriteria = "SELECT * FROM C_CG_Prod WHERE Data = #" & InputBox("Which day:") & "#"
Set rs = db.OpenRecordset(strFilterCriteria, dbOpenDynaset)
 
lol, never spotted that although you may end up with another Type Mismatch error if your database, as I said above, is set for ADO and not DAO.
 
Ya, this'll need a few tweaks before it'll run...
 

Users who are viewing this thread

Back
Top Bottom