没仔细看吧?简单的方法可以从MSysObjects中获得表名,然后通过列表框或者组合框的字段列表得到各个表的字段。这种方法无需代码,直接利用控件的属性设置即可。
除了这个方法外,还有其他一些方法。比如可以用ADO或者DAO获得表集和字段集。下面是通过ADO获得表集和字段名的两个自定义函数(没测试,你试试):
Public Function GetTables(ByVal cnn_str As String) As Variant
'引用:Microsoft ADO Ext. 2.8 for DDL and Security
'功能:获取数据表名数组
'参数:cnn_str--连接字符串
Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim i As Long
Dim Arr() As String
cnn.ConnectionString = cnn_str
cnn.Open
Set cat.ActiveConnection = cnn
For i = 0 To cat.Tables.Count - 1
ReDim Preserve Arr(i)
Set tbl = cat.Tables(i)
Arr(i) = tbl.Name
Next
GetTables = Arr
cnn.Close
Set cnn = Nothing
Set cat = Nothing
Set tbl = Nothing
End Function
Public Function GetTableFields(ByVal cnn_str As String, ByVal tbname As String) As Variant
'引用:Microsoft ADO Ext. 2.8 for DDL and Security
'功能:获取数据表列名数组
'参数:cnn_str--连接字符串,tbname---表名
Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim i As Long
Dim Arr() As String
cnn.ConnectionString = cnn_str
cnn.Open
Set cat.ActiveConnection = cnn
Set tbl = cat.Tables(tbname)
For i = 0 To tbl.Columns.Count - 1
ReDim Preserve Arr(i)
Arr(i) = tbl.Columns(i).Name
Next
GetTablesFields = Arr
Set cnn = Nothing
Set cat = Nothing
Set tbl = Nothing
End Function