edgarasb
edgarasb

Reputation: 45

invalid qualifier error accessing ListBox properties

Here lstName is a name of a list box in Access form.

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
  (...)

After calling a procedure:

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

I get error it this line:

If lstName.ItemsSelected.Count = 1 Then

Error is:

Invalid Qualifier

So basically VBA cannot understant that lstName. is a list from which it should find how many items are selected. I found that in VBA "strings are not objects, so there are no methods on the string variable that you can call".

There should be a simple solution, but I cannot find it. How to deal with this kind of problem?

Any help is highly appreciated!

Edgaras

Upvotes: 1

Views: 1077

Answers (3)

Fionnuala
Fionnuala

Reputation: 91376

You could pass the listbox as a listbox, a string will not have any properties, or you could pass the string and a form object, which might be safer.

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) ...

Upvotes: 1

Max Markov
Max Markov

Reputation: 936

You need either pass ListBox as Lsitbox inside cmdUp procedure

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

or find appropriate control using its name like:

Dim myListBox As ListBox = Me.FindControl(lstName)
if myListBox.ItemSelected.Count = 1 Then
...

Upvotes: 1

Jon Egerton
Jon Egerton

Reputation: 41579

lstName as you've passed it in will just be the string name of your listbox, not the actual listbox instance.

As this lstName is a string, calling lstName.ItemsSelected isn't valid.

You should be able to pass the listbox in instead:

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

Then call this using:

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

Upvotes: 1

Related Questions