我试图从三个查询中查看三个值。如果有任何查询记录数等于或大于1,我将显示主表单。我现在拥有的是三个查询和一个评估它们的if语句。
问题在于所有if语句都返回true。即使我知道第三个错误。
我正在使用Access构建查询窗口中的计数功能。
Private Sub testCount_Click()
Dim strSQL1
Dim strSQL2
Dim strSQL3
Dim NoData
NoData = "False"
strSQL1 = "SELECT DISTINCT Count(GRP4100Deltas.[TCTO Number]) AS [CountOfTCTO Number], Aircraft.FullTailNo, StatusCode.TCTOStatus " _
& "FROM StatusCode INNER JOIN (Aircraft INNER JOIN GRP4100Deltas ON Aircraft.[Serial Number] = GRP4100Deltas.[Serial Number]) ON StatusCode.StatusCode = GRP4100Deltas.[TCTO Status Code] " _
& "GROUP BY Aircraft.FullTailNo, StatusCode.TCTOStatus " _
& "HAVING (((StatusCode.TCTOStatus)='Completed'));"
strSQL2 = "SELECT DISTINCT Count(GRP4100Deltas.[TCTO Number]) AS [CountOfTCTO Number], Aircraft.FullTailNo, StatusCode.TCTOStatus " _
& "FROM StatusCode INNER JOIN (Aircraft INNER JOIN GRP4100Deltas ON Aircraft.[Serial Number] = GRP4100Deltas.[Serial Number]) ON StatusCode.StatusCode = GRP4100Deltas.[TCTO Status Code] " _
& "GROUP BY Aircraft.FullTailNo, StatusCode.TCTOStatus " _
& "HAVING (((StatusCode.TCTOStatus)='Not Completed'));"
strSQL3 = "SELECT DISTINCT Count(GRP4100Deltas.[TCTO Number]) AS [CountOfTCTO Number], Aircraft.FullTailNo " _
& "FROM StatusCode INNER JOIN (Aircraft INNER JOIN GRP4100Deltas ON Aircraft.[Serial Number] = GRP4100Deltas.[Serial Number]) ON StatusCode.StatusCode = GRP4100Deltas.[TCTO Status Code] " _
& "GROUP BY Aircraft.FullTailNo, StatusCode.TCTOStatus " _
& "HAVING (((StatusCode.TCTOStatus)='Not Applicable'));"
If (strSQL1 = 0) Then
NoData = "True1"
MsgBox ("1 has no data")
Else
NoData = "False"
MsgBox ("1 has data False")
End If
If (strSQL2 = 0) Then
NoData = "False"
MsgBox ("2 has no data")
Else
NoData = "True"
MsgBox ("2 has data")
End If
If (strSQL3 = 0) Then
NoData = "False"
MsgBox ("3 has no data")
Else
NoData = "True"
MsgBox ("3 has data")
End If
MsgBox ("There were SQL without entries NoData = " & NoData)
感谢您的帮助。 我正在为您获取一些测试数据。 马克西姆
答案 0 :(得分:0)
我对这个问题采取了不同的方法。由于我只关心三个查询中的任何一个是否具有一个或多个值。我更改了查询以更新countRecs表。然后运行三个单独的追加查询以填充表。然后,我使用了DCount函数来计算有多少记录。如果有多条记录,我将显示该表格。
感谢大家的帮助。 马克西姆