1

这里 lstName 是 Access 表单中列表框的名称。

Private Sub cmdUp(lstName As String, SQLName As String, IDName As String, ColumnName As String)
  Dim sText As String
  Dim pText As String
  'check: only proceed if there is a selected item
  If lstName.ItemsSelected.Count = 1 Then
  (...)

调用过程后:

Call cmdUp(lstSchemaName.Name, "eo_ListSchema", "SchemaID", "SchemaName")

我在这一行得到错误:

If lstName.ItemsSelected.Count = 1 Then

错误是:

Invalid Qualifier

所以基本上 VBA 无法理解那个 lstName。是一个列表,它应该从中找到选择了多少项。我发现在 VBA 中“字符串不是对象,因此字符串变量上没有可以调用的方法”。

应该有一个简单的解决方案,但我找不到。如何处理此类问题?

非常感谢任何帮助!

埃德加拉斯

4

3 回答 3

1

您需要在 cmdUp 过程中将 ListBox 作为 Lsitbox 传递

Private Sub cmdUp(lstName As ListBox, SQLName As String, IDName As String, ColumnName As String)

或使用其名称找到适当的控件,例如:

Dim myListBox As ListBox = Me.FindControl(lstName)
if myListBox.ItemSelected.Count = 1 Then
...
于 2012-09-05T11:28:31.350 回答
1

您可以将列表框作为列表框传递,字符串将没有任何属性,或者您可以传递字符串和表单对象,这可能更安全。

Call cmdUp(Me, lstSchemaName.Name, "eo_ListSchema", "SchemaID", "SchemaName")

Private Sub cmdUp(frm as Form, lstName As String, _
     SQLName As String, IDName As String, ColumnName As String)

   Frm(lstName) ...
于 2012-09-05T11:22:51.053 回答
1

lstName因为您传入的只是列表框的字符串名称,而不是实际的列表框实例。

由于这lstName是一个字符串,调用lstName.ItemsSelected无效。

您应该能够改为传递列表框:

Private Sub cmdUp(lstBox As ListBox, SQLName As String, IDName As String, ColumnName As String)
...

然后使用:

Call cmdUp(lstSchemaName, "eo_ListSchema", "SchemaID", "SchemaName")
于 2012-09-05T11:23:45.703 回答