Invalid Call or Procedure

S

Shelly Jackson

I have a hidden control on a form that reflects what selections a user has
made in a list box called RegListBx

The afterupdate procedure on the RegListBx is:

Private Sub RegListBx_AfterUpdate()

Dim varItem As Variant
Dim strSQL As String

For Each varItem In RegListBx.ItemsSelected
strSQL = strSQL & RegListBx.Column(0, varItem) & ","
Next varItem
strSQL = Left(strSQL, Len(strSQL) - 1)
[RegHidden] = strSQL
RegListBx = Null

End Sub

If the user makes selections, exits the box and then goes back to the box
and deselects all selections, the following error occurs:

Run-time error '5
Invalid procedure call of argument

The line: strSQL = Left(strSQL, Len(strSQL) - 1)
is highlighted in the debugger.

How can I prevent this from occurring when the user is deselecting all of
their choices in order to select other choices?

TIA
S. Jackson
 
C

Cheryl Fischer

Hi Shelly,

Perhaps you could surround that expression with a test for the Count of
selected items:

If RegListBx..ItemsSelected.Count > 0 Then
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top