我可以在 ms 访问中使用多个哈希表吗?



MS access是否提供哈希表,如hash{key1}{key2}{key3}[num]?或者任何解决方法?我在下面尝试模仿它,但我无法将 recordNum 数组添加到 dType 中。当我使用断点时,当 i 为 1 时,控制不能进入 If Not dType.exists(rst!serviceType) Then dType.Add rst!serviceType, recordNum(i) End If 的 if 子句。

Private Sub serviceInfo()
Dim dName As Object
Dim dNum As Object
Dim dType As Object
Dim recordNum(2048) As Integer
Set dName = CreateObject("Scripting.Dictionary") 'Create the Dictionary
Set dNum = CreateObject("Scripting.Dictionary") 'Create the Dictionary
Set dType = CreateObject("Scripting.Dictionary") 'Create the Dictionary
Set dbs = CurrentDb
qStr = "SELECT yearMonth, clName, certiNum, chName, chDateBirth, chNum, serviceType, serviceName " & _
       "FROM tblList " & _
       "WHERE tblList.chName=" & "'" & Me.Form.fchName & "';"
Set rst = dbs.OpenRecordset(qStr)
If Not (Err.Number = 0) Then ' if error
    MsgBox "An error occured (Error Number " & Err.Number & _
      ": " & Err.Description & ")"
    rst.Close
    Set rst = Nothing
    Set dbs = Nothing
    Exit Sub
ElseIf rst.BOF And rst.EOF Then
    cantFindRecordYoyang = 1
    'rst.Close
End If
With rst
        Dim i As Integer
        Do Until rst.EOF
            recordNum(i) = assetServiceTime(rst!serviceName) / 60
            If Not dType.exists(rst!serviceType) Then
                dType.Add rst!serviceType, recordNum(i)
            End If
            If Not dType.exists(rst!chNum) Then
                dNum.Add rst!chNum, dType
            End If
            If Not dType.exists(rst!chName) Then
                dName.Add rst!chName, dNum
            End If
            i = i + 1
        Loop ' // End do
End With
rst.Close
Set rst = Nothing
Set dbs = Nothing
End Sub

您没有移动记录集,并且可能必须更明确:

    Dim i As Integer
    Do Until rst.EOF
        recordNum(i) = assetServiceTime(rst!serviceName) / 60
        If Not dType.exists(rst!serviceType.Value) Then
            dType.Add rst!serviceType.Value, recordNum(i)
        End If
        If Not dType.exists(rst!chNum.Value) Then
            dNum.Add rst!chNum.Value, dType
        End If
        If Not dType.exists(rst!chName.Value) Then
            dName.Add rst!chName.Value, dNum
        End If
        i = i + 1
        rst.MoveNext
    Loop 
    rst.Close

最新更新