我目前正在使用记录集来获取我构建的查询的结果。从那里,我需要将报告的值与记录集中的结果进行比较,以便突出显示与记录集和报告匹配的值。
lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
Dim db As Database
Dim rs As DAO.Recordset
Dim strQuery As String
strQuery = "SELECT qry_Revision_History_Conversions_MaxR.Step_Int " _
& "FROM qry_Revision_History_Conversions_MaxR " _
& "Where (((qry_Revision_History_Conversions_MaxR.Step_Int) Is Not Null));"
If strQuery = Reports![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step] Then
[Reports]![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step].BackColor = lngYellow
Else
[Reports]![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step].BackColor = lngWhite
End If
对于测试,查询结果将是一个名为Step_Int的字段,它可以有一个条目或多个条目。例如,我为一个进程运行报告,查询将列出三个值,1,4和6,报告有13个步骤。在此报告中,步骤1,4和6应更改为黄色。这不起作用,我不确定我是如何做记录集的,或者我是如何使用它来将结果与报告进行比较。
答案 0 :(得分:0)
your strQuery is only a string with a select query on it, you're not supposed to compare it to anything really...
please check this link: http://www.utteraccess.com/wiki/index.php/Recordsets_for_Beginners it's a small tutorial on how to use recordsets.
basically put, you first build a query:
Dim strSQL As String
strSQL = "SELECT [column] FROM [Table]"
then create a recordset.
Dim rs As DAO.Recordset
then you "bind" the record-set to the results of the query.
Set rs = CurrentDb.OpenRecordset(strSQL)
now at this point, we have a recordset named 'rs' with the results of the query (assuming the query is correct and the data in it is valid).
we can go through the results via a loop:
If rs.Recordcount <> 0 Then
MsgBox( rs![column] & "" )
End If
When done, you are advised to handle the disposing of the references to free up your resources. although on newer version of Data Objects (later versions of DAO and ADO) you are not really required to do that.
rs.Close
Set rs = Nothing
*more info on the link i gave you at the top ..