【问题标题】:Access VBA - adding row with multiple columns访问 VBA - 添加具有多列的行
【发布时间】:2015-11-07 00:41:49
【问题描述】:

我正在尝试将多列项添加到使用 VBA 访问的 ListBox。不过,我这辈子都想不出该怎么做。互联网上似乎有多种方法,但没有一种对我有用。

这是一个例子:

Sub AddMultipleColumn()
'Add multiple Columns to a listbox
ListBox1.Clear 'Make sure the Listbox is empty
ListBox1.ColumnCount = 3 'Set the column Amount
'Fill the Listbox
ListBox1.AddItem "Row Number 1" 'Additem creates a new row
ListBox1.List(0, 1) = "Column Number 2" 'List(x,y) X is the row number, Y the column number
ListBox1.List(0, 2) = "Column Number 3"
ListBox1.List(0, 3) = "Column Number 4"
End Sub

http://visiblevisual.com/jupgrade/index.php/general-net/77-multiple-columns

这是我的代码(已经配置为三列):

lst_TemplateEditorList.AddItem "1"
lst_TemplateEditorList.List(0, 0) = "1"
lst_TemplateEditorList.List(0, 1) = "2"
lst_TemplateEditorList.List(0, 2) = "3"

但我在“lst_TemplateEditorList.List”上收到编译错误“找不到方法或数据成员”,因为没有 List 方法/属性。

我发现了一些使用“Column”而不是“List”的东西,但这不起作用,并且一些没有“AddItem”的参数,这也会导致错误:

lst_TemplateEditorList.AddItem
lst_TemplateEditorList.Column(0, 0) = "1"
lst_TemplateEditorList.Column(0, 1) = "2"
lst_TemplateEditorList.Column(0, 2) = "3"

但大多数人似乎建议第一个应该有效,例如:

Adding items in a Listbox with multiple columns

vba listbox multicolumn add

它似乎应该如此简单......但我很难过。谁能告诉我我做错了什么?

谢谢

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    Access 中的列表框与其他 Office 程序中的列表框具有不同的属性/方法集(它们属于“Microsoft Forms”对象模型)

    https://msdn.microsoft.com/en-us/library/office/ff195480.aspx

    在 Access 中,您只需像在 RowSource 属性中一样为 RowSourceType = Value List 添加多列数据,用分号分隔。

    With Me.lst_TemplateEditorList
        .AddItem "1;2;3"   ' first row
        .AddItem "4;5;6"   ' second row
    End With
    

    编辑

    Access 2010 开发人员帮助增加了混乱:如果您搜索 List,您会得到 Forms-列表框及其属性,包括 .List。您必须仔细观察才能注意到您已经离开Access 领域并进入了Microsoft Forms 领域。德语访问在这里,但你明白了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-17
      • 2017-09-12
      • 1970-01-01
      相关资源
      最近更新 更多