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

Posted on 2006-04-10
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

Private Sub cboModes1_Click()
    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
Question by:holemania
    LVL 48

    Accepted Solution

    ListIndex is Zero based, so you should try like this instead:

    rsData.Move cboModes1.ItemData(cboModes1.ListIndex)  


    Author Comment

    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.

    Author Comment

    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.  

    Author Comment

    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.

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


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now