下面的代码是我在网站上找到的,可以把表“固定资产登记审批单”的所有字段名赋值给变量Tbname,然后 通过MsgBox分行显示。
想请各位大哥帮忙改一下,改成赋值给组合框,也就是说组合框的数据源就是表的字段名。谢谢!
Dim rst As New ADODB.Recordset
Dim Tbname As String
Dim FieldsCount As Integer
Dim i As Integer
Tbname = "固定资产登记审批单"
rst.Open "select top 1 * from " & Tbname, CurrentProject.Connection
FieldsCount = rst.Fields.Count
For i = 0 To FieldsCount - 1
Tbname = Tbname & vbNewLine & rst.Fields(i).Name
Next
MsgBox Tbname
rst.Close
For i = 0 To FieldsCount - 1
Tbname = Tbname & rst.Fields(i).Name & ";"
Next
If Tbname <> "" Then
Tbname = Left(Tbname, Len(Tbname) - 1)
End If
Me.组合框名.RowSourceType = "Value List"
Me.组合框名.RowSource = Tbname