1

我正在尝试获取访问报告以确定文本字段 (NH) 是否与相同的 ID 不匹配。例如,ID 179 有两行,但每个 NH 不同(12345 和 12346)。我正在尝试使用 DCount 来计算 NH 不匹配的 ID,如果它是相同的 ID,但我无法弄清楚。

这是我的代码示例:这应该获取匹配的 ID,例如 179 和 179,并检查 NH 以查看它们是否相同,如果不同则返回计数。

CheckValue = DCount([ID], "vTestQuery", "[NH] <> '" & [NH] & "'" And "[ID] ='" & [ID] & "'")

如果 CheckValue 具有实际值,这将为 Me.txtColor 提供一个值,用于我设置的条件格式。

If (CheckValue > 0) Then
Me.txtColor = CheckValue

我还需要检查报告中的所有记录,并计算每个匹配的 ID 与不同的 NH,以便我可以标记不同的 NH。

有人可以让我知道我是否在正确的轨道上,如果是这样,可以解决我的困境。

非常感谢你!

第一次编辑

样本数据:

+-----+------------+------------+------------+-------------+
| ID  | FullName   | DateOfServ | AccountNum | NoteH       |
+-----+------------+------------+------------+-------------+
| 179 | Test, Jane | 8/1/2015   | 458585     | AAA-1111111 |
| 180 | Test, Paul | 8/1/2015   | 458586     | AAA-2222222 |
| 181 | Test, John | 8/2/2015   | 458587     | AAA-3333333 |
| 214 | Test, Alex | 8/3/2015   | 458588     | AAA-4444444 |
| 214 | Test, Alex | 8/3/2015   | 458588     | AAA-4444445 |
| 215 | Test, Alex | 8/3/2015   | 458589     | AAA-5555555 |
| 215 | Test, Alex | 8/3/2015   | 458589     | AAA-5555555 |
+-----+------------+------------+------------+-------------+

所以我需要报告做的是突出显示或更改匹配但具有不同 NH 的 ID 的文本颜色 例如,记录 214 有两条记录,除了 NoteH 之外,所有的数据完全相同,我需要突出显示这两个 NoteH或文本已更改。我把有问题的 NoteH 都加粗了。让我知道这是否有帮助。

第二次编辑

因此,该查询适用于所有具有重复 NoteH 的重复 ID,但如果 NoteH 不同,它仍然只注册一个 ID。我添加了一个 IDCount,以显示由于 NoteH 不同,查询如何将每个 214 ID 注册为不同的。

结果如下:

+-----+------------+---------+
| ID  | NoteCount  | IDCount |
+-----+------------+---------+
| 214 | 1          | 1       |
+-----+------------+---------+
| 214 | 1          | 1       |
+-----+------------+---------+
| 212 | 2          | 2       |
+-----+------------+---------+

I need a way to have the report recognize that 214 is a duplicate field but the NoteH is not the same. It is really close to working everything else you suggested works great!!!

3rd EDIT

SELECT May.ID, Count(May.ID) AS IDCount, FROM May INNER JOIN 
Count(CodeRyteCodingResults.[Note Handle]) AS NoteCount
CodeRyteCodingResults ON May.[Accession #] =
CodeRyteCodingResults.[Accession Number]
GROUP BY May.ID;
4

1 回答 1

0

Use Aggregate Queries and Conditional Formatting

Create separate queries to get counts of unique notes per ID. It will look something like this (I'm using two queries):

UniqueNotesQuery

SELECT ID, NoteH
FROM BaseTable
GROUP BY ID, NoteH

NoteCountsQuery (this queries the first one)

SELECT ID, Count(NoteH) AS NoteCount
FROM UniqueNotesQuery
GROUP BY ID;

Then join this as part of your report query. It will look something like this:

SELECT BaseTable.*, NoteCountsQuery.NoteCount
FROM BaseTable INNER JOIN NoteCountsQuery
ON BaseTable.ID = NoteCountsQuery.ID

In your report, write a rule in the Conditional Formatting of the textboxes. Something like this:

[NoteCount] > 1

These queries above are just written from scratch, so they are untested, and you will need to flesh them out for your project.

References:

于 2015-07-28T15:30:13.403 回答