【发布时间】:2014-07-22 16:57:31
【问题描述】:
大家好我处于两难境地我试图通过比较记录来找到同一个人可能创建的多个帐户,我的主要问题是如何将当前行值与下一个值进行比较?我的意思是这样 MI(i)=MI(i+1) "MI" 是我要定位的字段,i 代表当前行,所以假设要做的是将当前值与下一个值进行比较.但它似乎在 vba 中不起作用,它是以不同的方式完成的吗?要过滤我应该使用 rs.Filter 还是应该使用 Me.Filter 因为我希望过滤后的表格显示在我的拆分表单中。
我正在使用的当前示例表:
Number MI First Name Last Name DOB
15241543 123456789 James Matheson 2/25/1980
15241543 123456789 Jams Matheson 2/25/1980
12345679 124512451 Monroe Matheson 3/25/1980
12345679 124512451 Monro Matheson 3/25/1980
54789654 152415241 Dilan Pumley 4/23/1970
54789658 154215246 Michael Lan 1/30/1989
应该出现的最终表格是这样的:
Number MI First Name Last Name DOB
15241543 123456789 James Matheson 2/25/1980
15241543 123456789 Jams Matheson 2/25/1980
12345679 124512451 Monroe Matheson 3/25/1980
12345679 124512451 Monro Matheson 3/25/1980
Private Sub buttonSort_Click()
Dim i As Integer
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("deleteYo")
For i = 0 To rs.RecordCount - 1
'Comapred the current DOB cell value to the next DOB cell value and some other conditions are set such as Current First Name does not equal the next First Name value
If DOB(i) = DOB(i + 1) And [First Name](i) <> [First Name](i + 1) Or [Last Name](i) <> [Last Name](i + 1) And Number(i) = Number(i + 1) Or MI(i) = MI(i + 1) Then
'Filters the current value if the conditon is passed
Me.Filter = "[First Name]" & [First Name](i).Value & "'"
'Filter the next value also to append the filtered values so that they will not be overwritten.
Me.Filter = Me.Filter & "[First Name]" & [First Name](i + 1).Value & "'"
Else
End If
rs.MoveNext
Next i
Me.FilterOn = True
rs.Close
Set rs = Nothing
db.Close
End Sub
请注意,我已尝试使用带有 SQl 语句的查询,但它无法正常工作,可能是因为该数据实际上是数百万条记录,还因为 UI 在表单中,并且当应用过滤值时,我想要它们显示在拆分表单底部的表格中。
【问题讨论】:
标签: ms-access vba filtering recordset