Excel VBA从字段where和子句中选择计数

Excel VBA从字段where和子句中选择计数,excel,ms-access,excel-2007,vba,Excel,Ms Access,Excel 2007,Vba,这看起来很简单,但在执行以下vba语句时出现错误: Dim currentmth As String currentmth = Sheets("Data").Range("f3") ----this stores the month name strSql = "SELECT count(Emails_Submitted) As Total FROM tablename WHERE Emails_Submitted > 1 '" & tc_mth = currentmth &

这看起来很简单,但在执行以下vba语句时出现错误:

Dim currentmth As String
currentmth = Sheets("Data").Range("f3") ----this stores the month name
strSql = "SELECT count(Emails_Submitted) As Total FROM tablename WHERE Emails_Submitted > 1 '" & tc_mth = currentmth & "'"

cn.Open strConnection
Set rs = cn.Execute(strSql)
countfrmdb = rs.Fields(0)
cellref = countfrmdb

错误消息:无效的sql语句

语法错误。将
>1'&tc_mth=currentmth&“'”
更改为
>1和tc_mth='¤tmth&“'”
@ScottHoltzman我认为您提供的现在可以工作了,但我得到了另一个错误“表达式中的数据类型不匹配”。我猜这是因为我正在计算的列包含以文本形式存储的数字。有什么解决方法吗?确保currentmth变量的数据类型与tc_mth字段的数据类型匹配。@ScottHoltzman非常感谢,它现在工作得很好!!