ADO statement

crowegreg

Registered User.
Local time
Today, 12:47
Joined
Feb 28, 2011
Messages
108
Using a variable as a field name, I'm unable to get this query statement to work. I've manually entered the statement into the query design, and I receive the same error of "data type mismatch in criteria expression." Here's the vital info:
This is the SQL statement that was created within the query design and it works:
SELECT tblMasterTitleTopics.ReferenceID, tblMasterTitleTopics.Africa FROM tblMasterTitleTopics WHERE (((tblMasterTitleTopics.ReferenceID) = "9999"))

This statement was created in VBA code, and I receive the error message:

stritem = "9999"
str0 = "Africa"

strquery = "SELECT [tblMasterTitleTopics].[ReferenceID], [tblMasterTitleTopics].["
strquery = strquery & str0 & "] FROM tblMasterTitleTopics WHERE ((([tblMasterTitleTopics].[ReferenceID]) = "
strquery = strquery & Chr(34) & stritem & Chr(34) & "))"

I think the problem is because I'm using a variable to create the field name, but I don't know how to fix it. Thanks in Advance!!
 
The concatenation of the variables looks correct. Are you sure that ReferenceID is text and not a number?
 
YOU'RE GOOD!! That was it. Thanks!!
 

Users who are viewing this thread

Back
Top Bottom