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

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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ListIndex is Zero based, so you should try like this instead:

rsData.Move cboModes1.ItemData(cboModes1.ListIndex)  


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
holemaniaAuthor Commented:
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.
holemaniaAuthor Commented:
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.  
holemaniaAuthor Commented:
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)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.