troubleshooting Question

Complex Select statement syntax in VBA

Avatar of rfreud
rfreud asked on
4 Comments1 Solution64 ViewsLast Modified:
Hello - I am having trouble with the syntax for a SELECT statement that involves selecting records between two dates and where the desired records meet two conditions that are characterized by strings.  The portion of the select statement that selects records between the two dates works fine all by itself, but when I try to add the string parameters I get a data type mismatch error.  The string parameters appear to be numbers, but they are actually strings.  They are strings assigned to states and counties. They are known as FIPS codes.  Each state has a FIPS code and each county within each state has a FIPS code.  Again, the values look like integers, but they are strings.  Here is the line of code that selects records that fall within two dates that works fine:
rst2.Open "Select * From [qry_NumberOfClosings_ByCounty] where clsng_dt between #" & dStartDate & "# AND #" & dEndDate & "#"

Here is the line with addition of the attempt to add the FIPS codes as additional parameters.  (BTW, the variable names are dimensioned correctly as strings):

rst2.Open "Select * From [qry_NumberOfClosings_ByCounty] where clsng_dt between #" & dStartDate & "# AND #" & dEndDate & "#" And """fips_st_cd = " & strStateFIPS & """" And """fips_cnty_cd =" & strCountyFIPS & """"

In this case, fips_st_cd and fips_cnty_cd are columns in the underlying query.  

Thanks very much in advance for your help.
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros