我创建了一个公共函数,以便我可以在Access窗体上调用它,并在文本框控件中显示结果。这是公共职能:
Public Function CurrRecs(xRecName As String, frmName As Form, tblCount As String)
If Forms(frmName).NewRecord Then
frmName.txtCurrRec = "New " & xRecName & " Record"
Else
frmName.txtCurrRec = CStr(frmName.CurrentRecord) & " of " & _
DCount("ID", tblCount) & " " & xRecName & "s"
End If
End Function
这就是我在Form_Current()
上的内容CurrRecs(" RecordType"," frmCurrentForm"," tblGetCountFromHere")
我收到编译错误:预期:=
任何人都知道我做错了什么?
答案 0 :(得分:1)
错误是因为您将frmName
声明为表单,但在一个地方将其用作字符串,而在另一个地方使用表单
此外,如果您想要表计数,请使用Form.RecordSet.RecordCount
,而不是精心设计的DCount
改写为:
Public Function CurrRecs(xRecName As String, frmName As String)
Dim frm As Form
Set frm = Forms(frmName)
If frm NewRecord Then
frm.txtCurrRec = "New " & xRecName & " Record"
Else
frm.txtCurrRec = CStr(frm.CurrentRecord) & " of " & _
frm.RecordSet.RecordCount & " " & xRecName & "s"
End If
End Function