错误描述:
实时错误'3075'
字符串的语法错误 在查询表达式'tableName='C:\Program Files\Zontec\Synergy2000Engineer Demo\tutor1.ztb' and ID1='Lot # 78'中
出错处:
Set dbrecordset = db.OpenRecordset("select tableName,averageObs from tableVariableValue where tableName=" + "'" + dataTableName + "'" + "and ID1=" + "'" + SID1 + "'")
部分代码是:
Function countAveValue(ByVal dataTableName As String, ByVal SID1 As String, ByVal SID2 As String, ByVal SID3 As String)
averageValue = 0
If Trim(SID1) <> "ID1" Then
Set dbrecordset = db.OpenRecordset("select tableName,averageObs from tableVariableValue where tableName=" + "'" + dataTableName + "'" + "and ID1=" + "'" + SID1 + "'")
If Trim(SID2) <> "ID2" Then
Set dbrecordset = db.OpenRecordset("select tableName,averageObs from tableVariableValue where tableName=" + "'" + dataTableName + "'" + "and ID1=" + "'" + SID1 + "'" + " and ID2=" + "'" + SID2 + "'")
End If
ElseIf Trim(SID1) = "ID1" Then
If Trim(SID2) <> "ID2" Then
Set dbrecordset = db.OpenRecordset("select tableName,averageObs from tableVariableValue where tableName=" + "'" + dataTableName + "'" + "and ID2=" + "'" + SID2 + "'")
End If
End If
end function我用的是dao连接access数据库,我是个新手,查来查去,查不出哪里错了,请高手们帮帮忙,不胜感激!
实时错误'3075'
字符串的语法错误 在查询表达式'tableName='C:\Program Files\Zontec\Synergy2000Engineer Demo\tutor1.ztb' and ID1='Lot # 78'中
出错处:
Set dbrecordset = db.OpenRecordset("select tableName,averageObs from tableVariableValue where tableName=" + "'" + dataTableName + "'" + "and ID1=" + "'" + SID1 + "'")
部分代码是:
Function countAveValue(ByVal dataTableName As String, ByVal SID1 As String, ByVal SID2 As String, ByVal SID3 As String)
averageValue = 0
If Trim(SID1) <> "ID1" Then
Set dbrecordset = db.OpenRecordset("select tableName,averageObs from tableVariableValue where tableName=" + "'" + dataTableName + "'" + "and ID1=" + "'" + SID1 + "'")
If Trim(SID2) <> "ID2" Then
Set dbrecordset = db.OpenRecordset("select tableName,averageObs from tableVariableValue where tableName=" + "'" + dataTableName + "'" + "and ID1=" + "'" + SID1 + "'" + " and ID2=" + "'" + SID2 + "'")
End If
ElseIf Trim(SID1) = "ID1" Then
If Trim(SID2) <> "ID2" Then
Set dbrecordset = db.OpenRecordset("select tableName,averageObs from tableVariableValue where tableName=" + "'" + dataTableName + "'" + "and ID2=" + "'" + SID2 + "'")
End If
End If
end function我用的是dao连接access数据库,我是个新手,查来查去,查不出哪里错了,请高手们帮帮忙,不胜感激!
and之前加空格tableVariableValue:这个是你的table名称么?还是VariableValue是你的table名另外你检查的时候把datatablename和id1都换成比较普通的值,比如tb1与hello。看看还是不是出现字符串错误
"from tableVariableValue "& _
"where tableName='"& trim(dataTableName) &"' and ID1='"& trim(SID1) &"'"
我的tableVariableValue中的数据是通过dll从其它程序导出来的,其中ID1,ID2,ID3的长度是固定20,值是这样的,如:"Lot # 78 ",(Lot # 78后面还有个小下标)
所以我在用ID号作为条件进行查询时出现了困难,怎样设定SID的值使它能与ID相匹配,不致于查询为空呢?