queryResult是一个2行5列的二维数组
将您的组合框 ColumnCount 属性设置为 5
cbSTPScrewedMaterial.ColumnCount = 5
并全部显示
此外,queryResult(1) 试图将二维数组作为一维数组访问,从而导致错误
您可以使用函数从给定的二维数组行中返回一维数组,如下所示
Option Explicit
Function GetQueryRow(arr As Variant, iRow As Long) As Variant
Dim j As Long
ReDim arrRow(LBound(arr, 2) To UBound(arr, 2)) As Variant
For j = LBound(arr, 2) To UBound(arr, 2)
arrRow(j) = arr(iRow, j)
Next j
GetQueryRow = arrRow
End Function
使用如下:
Dim queryResult As Variant
Dim queryRow As Variant
queryResult = RetrieveRecordset("SELECT * FROM Materials;")
queryRow = GetQueryRow(queryResult, 1)
或“直接”
Dim queryRow As Variant
queryRow = GetQueryRow(RetrieveRecordset("SELECT * FROM Materials;"), 1)
甚至“更直接”
MsgBox GetQueryRow(RetrieveRecordset("SELECT * FROM Materials;"), 1)(1)