【发布时间】:2019-12-17 15:00:23
【问题描述】:
我在 Access 中的查询的 VBA 函数存在问题。
我有一个表“tbldata”
Equipment Last Inspection
420-413 2019-06-15
440-433 2019-06-15
402-483 2019-06-29
420-413 2019-12-12
还有一个查询“qryunpair”
UnpairEquipment
420
413
440
433
402
483
我想要实现的是:
Equipment Latest Date
420 2019-12-12
413 2019-12-12
440 2019-06-15
433 2019-06-15
402 2019-06-29
483 2019-06-29
我编写了以下代码,但是当我运行它时,它没有返回任何值。 有解决办法吗?
Function typeinspection(Source As String) As String
Dim Rst As Recordset
Dim Rst2 As Recordset
Dim s As String
s = ""
Set Rst = CurrentDb.OpenRecordset("tbldata")
Set Rst2 = CurrentDb.OpenRecordset("qryunpair")
While Not Rst.EOF
If InStr(Source, Rst2.Fields("UnpairEquipment") > 0) Then _
s = Rst.Fields("Last Inspection")
Rst.MoveNext
Wend
Set Rst = Nothing
Set Rst2 = Nothing
typeinspection = s
End Function
【问题讨论】: