在Access平台中有这么一句代码
Forms!usysfrmFind!cobfldName.RowSource = "报销日期;1;类别名称;3;员工姓名;3;报销金额;2;报销摘要;3;"
在编写程序时经常会去逐个填写这一串字段名,有时还会因为笔误把字段名打错,在此介绍一个函数,可以方便的获得这些字符串
Function GetFieldList(tblname As String) As String
Dim rst As New ADODB.Recordset
rst.Open "select * from " & tblname & " where 1<>1", CurrentProject.Connection
For i = 0 To rst.Fields.Count - 1
Debug.Print rst(i).Name & ";;";
Next
End Function
使用时:
sub dddd()
getfieldlist("报销明细主窗体查询")
end sub
然后在立即窗口中复制就可以了,字段类型自己写。