當我不知道數組的大小時,如何將字段名稱添加到數組中?在我下面的兩個函數中,我能夠填充表沒有問題,但是當我嘗試創建數組時,它只會打印表中的第一條記錄。我必須做什麼才能創建具有所有值的數組?創建一維動態數組
Function PopulateTable()
Set rs1 = db.OpenRecordset("MasterList")
For Each fld In rs1.Fields
StrSQL = "INSERT INTO HoldTable (FieldList) VALUES ('" & fld.Name & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL StrSQL
Next
'Create array of all fld.Name Values
PopulateArray
End Function
Function PopulateArray()
Dim rstData As DAO.Recordset
Dim v As Variant
Dim cn As Variant
Set rstData = CurrentDb.OpenRecordset("select fieldlist from HoldTable")
v = rstData.GetRows(rstData.RecordCount)
For Each cn In v
Debug.Print CStr(cn)
Next
End Function
從[文檔](https://msdn.microsoft.com/en環-us/library/office/ff194427.aspx)(我強調),「GetRows返回***二維***數組。」 – Comintern