?
Solved

Run-time error '381'" Invalid Property array index

Posted on 2006-04-10
4
Medium Priority
?
8,522 Views
Last Modified: 2011-08-18
I am in need of assistance on an error that I'm getting.  I have created a form that when load goes and read an excel spreadsheet and populate a combo box.  If the user clicks on the combo box, it will populate the text box base on the specified selection.

The error that I'm getting is "Run-time error '381': Invalid property array index."  This error will only occur if I select the first selection from the combo box.  Anything else seems excluding the first selection from the combo box seems to work fine.

Below is my code:

rsData.Open "Select * From MODES", conn, adOpenDynamic, adLockOptimistic

Do Until rsData.EOF
    If Not IsNull(rsData.Fields(0)) Then
    cboModes1.AddItem rsData.Fields(0)
    cboModes1.ItemData(rsData.AbsolutePosition - 1) = rsData.AbsolutePosition
    End If
    rsData.MoveNext
Loop



Private Sub cboModes1_Click()
    rsData.MoveFirst
    rsData.Move cboModes1.ItemData(cboModes1.ListIndex - 1)         ------------------------->  Here is where i get the error if I select the first selection from the list.
    txtModes1.text = rsData.Fields(1)
End Sub
0
Comment
Question by:holemania
  • 3
4 Comments
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 375 total points
ID: 16419085
ListIndex is Zero based, so you should try like this instead:

rsData.Move cboModes1.ItemData(cboModes1.ListIndex)  

?
0
 

Author Comment

by:holemania
ID: 16419476
If I set it to as you mentioned above, it does not error out.  However instead of getting Listindex 0 to show i'm getting listindex1 for my description.  

For example A1 and B1 should tied to each other and listed as Listindex 0, but now when I select from the combo box the value of A1, it displays value of B2 instead of B1.  \

Shutdown --------All valve closed and lights off.
Run----------------Chamber set to a point.

If "Shutdown" is selected, i get "Chamber set to a point".  With my example, it corresponds however my first selection gives me a run time error.  I am assuming it might have to do with my form load cboModes1.ItemData(rsData.AbsolutePosition - 1) = rsData.AbsolutePosition.  I thought that if 1-1 should equal 0, but for some strange reason that line is giving me index of 1.
0
 

Author Comment

by:holemania
ID: 16421135
Also as a side note if I select the last value "Run" from the combo box, it gives me an error "Run-time error '94': Invalid use of Null".  It seems that it is skiping an index.  
0
 

Author Comment

by:holemania
ID: 16421445
I kind of figure out a work around.  WIth your example I was able to select the first item on the list and with mine I was able to select last item on the list.  So I combine both and it seems to work.

rsData.MoveFirst
If cboModes1.ListIndex = 0 Then
     rsData.Move cboModes1.ItemData(cboModes1.ListIndex)
Else
    rsData.Move cboModes1.ItemData(cboModes1.ListIndex - 1)
End IF
txtModes1.text = rsData.Fields(1)


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question