我有一个开放的子表单(在表单内)。该子表单基于查询并包含多个记录。我想搜索子窗体以查找是否有记录具有= true的字段值。
搜索后,最好的建议是使用sql。这就是我正在使用的:-
Dim iRecCount As Integer
Dim strRecCount As String
Dim vInvoiceID as Variant
vInvoiceID = [Forms]![Invoices]![InvoiceID].Value
strRecCount = "SELECT Count(*) AS CountOfSlotID FROM (Appointments INNER JOIN Students ON Appointments.StudentID = Students.StudentID) INNER JOIN Invoices ON Appointments.InvoiceID = Invoices.InvoiceID WHERE (((Appointments.InvoiceID)=" & vInvoiceID & ") AND ((Students.PAYG)=Yes));"
iRecCount = CurrentDb.OpenRecordset(strRecCount).Fields(0).Value
If iRecCount > 0 Then
[Forms]![Invoices]![Temp Termly].Value = True
Else: [Forms]![Invoices]![Temp Termly].Value = False
End If
如果我将SQL字符串复制并粘贴到查询中,它将为我提供正确的结果(实际上是从有效的查询中获得了SQL字符串)。但是,无论如何,此代码都将返回零。我认为这条线有问题:-
iRecCount = CurrentDb.OpenRecordset(strRecCount).Fields(0).Value
任何建议或替代解决方案都将有所帮助。
您将使用RecordsetClone:
Dim rs As DAO.Recordset
Dim Found As Boolean
Set rs = Me!SubformControlName.Form.RecordsetClone
If rs.RecordCount > 0 Then
rs.FindFirst "[Temp Termly] = True"
Found = Not rs.NoMatch
End If
Set rs = Nothing
If Found = True Then
' Success.
End If
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句