小编R. *_*J. 的帖子

使用变量引用类属性?

我有一个集合(employees员工)含有name,id,office,和officeto领域.我需要在等间距列中打印出这些信息.所以我需要找到最长的字符串名称,office,officeto ...的长度,并添加空格以使列间隔相等.
我知道如何使用记录集将字段名称发送到函数中.所以我的问题是......是否可以通过使用变量(类似于rst![fieldname])来引用类属性(name,office,officeto).我试着把它设置成一个字段上的记录集循环,但它没有编译.错误是class.property未定义.

Public Function PropertyLen(ByVal Property As String, ByRef Employees As colEmployees) As Integer

'This function uses a passed in class property, and returns the len of the longest class property in collection

On Error GoTo ErrorHandler:

Dim Emp As clsEmployee
Dim intLen As Integer 
Dim lngCount As Long

For lngCount = 1 To Employees.Count

       Set Emp = Employees.Item(lngCount)

       If Len(Trim(Emp.Property)) > intLen Then
            intLen = Len(Trim(Emp.Property))
       End If …
Run Code Online (Sandbox Code Playgroud)

vba access-vba

7
推荐指数
2
解决办法
4228
查看次数

标签 统计

access-vba ×1

vba ×1