访问 vba:列表框 additem 多列截断逗号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7748897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:15:36  来源:igfitidea点击:

Access vba: listbox additem multicolumn truncating on comma

ms-accessvba

提问by Rick

I have a combobox with two colunms, but the first is hidden that adds values onto a listbox in the same manner. I am noticing that the list box is truncating the string in the second column.

我有一个带有两个列的组合框,但第一个是隐藏的,它以相同的方式将值添加到列表框中。我注意到列表框正在截断第二列中的字符串。

This is my code thus far where cmbPart is the combobox and lstPart is the listbox.

到目前为止,这是我的代码,其中 cmbPart 是组合框, lstPart 是列表框。

Me.lstPart.AddItem (CStr(Me.cmbPart.Value) & " ;" & CStr(Me.cmbPart.Column(1, Me.cmbPart.ListIndex)))

I notice that that when there is a comma (,) in the string it stops displaying the rest from Me.cmbPart.Column(1, Me.cmbPart.ListIndex).

我注意到,当字符串中有逗号 (,) 时,它会停止显示Me.cmbPart.Column(1, Me.cmbPart.ListIndex).

How can I stop the behavior?

我怎样才能停止这种行为?

回答by Rick

Aperently strings with commas in to be added to a multicolunm listbox bust be enclosed in single quotes.

显然,要添加到多列列表框的带逗号的字符串用单引号括起来。

Me.lstPart.AddItem (CStr(Me.cmbPart.Value) & " ;" & CStr("'" & Me.cmbPart.Column(1, Me.cmbPart.ListIndex)) & "'")