0

私はリストボックスを持っています(図を参照)。このリストボックスはRecordSourceに関連付けられておらず、エンドユーザーによって他のコントロールの選択に基づいて動的に構築されます。これまで私はこれに関してあまり問題を抱えていませんでしたが、この現在の動的クエリの状況では、列は完全に一定ではありません。使用されているRecordSetはCrossTabクエリであるため、CrossTabクエリの4分の1には、5列、次の8列、および次の3列が含まれる場合があります。

私が実装したリストボックスのほとんどには、予測できる静的な量の列がありますが、この状況では、列の数を一貫して予測することはできません。

ColumnHeadsプロパティをに設定したYesので、問題はありません。設定した操作ColumnHeadsの前に、VBAでプロパティをリセットすることもできます。AddItem

問題のリストボックス(lstCategoryPG)内/周辺で操作するために使用しているロジック:

If lstCatType.ListIndex >= 0 Then
'Application.Echo False    'Turn off Screen Updating

    Dim crt As String: crt = "crt_CategoryPG"   'Cross-Tab Query
    Dim cttbl As String: cttbl = CreateCTTable(crt) 'Create Table to store the Cross-Tab information
    Dim sql As String: sql = SQLSelect(cttbl)
    Dim flds As DAO.Recordset: Set flds = CurrentDb.OpenRecordset(sql)
    Dim fldwd As String     'Store the Field Width pattern
    fldwd = "0"";0"";2"""   'Handles `tid` and `cid` columns in the ListBox
    'Assign the number of columns based on the number of fields in CTtable
    lstCategoryPG.ColumnCount = flds.Fields.Count

    Dim fld As Long
    For fld = 3 To (flds.Fields.Count - 1)
        fldwd = fldwd & ";.75"""
    Next
    flds.Close: Set flds = Nothing

    lstCategoryPG.ColumnWidths = fldwd

    sql = SQLSelect(cttbl, , ("tid = " & lstCatType.Value))

    lstCategoryPG.Enabled = True
    lstCategoryPG.ColumnHeads = True
    RefreshControl CurrentDb, lstCategoryPG, sql, , False
'Application.Echo True     'Turn Screen Updating back on
End If
4

1 に答える 1

0

根性に入り、列ヘッダーがクエリフィールドからプルされない理由を確認できるようになるまで、暫定的なブレークフィックスソリューションが機能しました。

If lstCatType.ListIndex >= 0 Then
'Application.Echo False    'Turn off Screen Updating

    Dim crt As String: crt = "crt_CategoryPG"   'Cross-Tab Query
    Dim cttbl As String: cttbl = CreateCTTable(crt) 'Create Table to store the Cross-Tab information
    Dim sql As String: sql = SQLSelect(cttbl)
    Dim flds As DAO.Recordset: Set flds = CurrentDb.OpenRecordset(sql)
    Dim fldwd As String, fldhd As String      'Store the Field Width pattern and Field Header Row
--> fldhd = "-1;-1;Category"
    fldwd = "0"";0"";2.5"""   'Handles `tid` and `cid` columns in the ListBox
    'Assign the number of columns based on the number of fields in CTtable
    lstCategoryPG.ColumnCount = flds.Fields.Count

    Dim fld As Long
    For fld = 3 To (flds.Fields.Count - 1)
        fldwd = fldwd & ";.75"""
-->     fldhd = fldhd & ";" & flds.Fields(fld).Name
    Next
    flds.Close: Set flds = Nothing

    lstCategoryPG.ColumnHeads = True
    lstCategoryPG.ColumnWidths = fldwd

    sql = SQLSelect(cttbl, , ("tid = " & lstCatType.Value))

    lstCategoryPG.Enabled = True
    RefreshControl CurrentDb, lstCategoryPG, sql, , False
--> lstCategoryPG.AddItem fldhd, 0
'Application.Echo True     'Turn Screen Updating back on
End If
于 2012-08-31T14:00:49.820 に答える