Solved

vb6 run time error '381' Invalid property array index.

Posted on 2014-03-05
3
1,564 Views
Last Modified: 2014-03-13
When I run the code seen below, I get the Run Time error '381' Invalid property array index. The line the debugger points to is...
.fields("fo_rackType") = Me.cboRackType.ItemData(Me.cboRackType.ListIndex)

Any ideas on how to fix this error?  Thanks in Advance,
Here's the code...

Private Sub cmdInsert_Click()
    'take the current Zone that you are on, then make the endZone the
    'endZone of the new Zone.  Have the user pick tHe beginning zone and
    'make the end of the old zone the zone prior to the beginning of the
    'new zone
   
    Dim lngZoneNumb As Long
    Dim rowZoneRow As Integer
    Dim strZoneCode As String
    Dim strZoneLoc As String
   
    If Not rsZoneConfig.EOF Then
        If Not Trim(rsZoneConfig.fields("StartZoneCode")) = Trim(rsZoneConfig.fields("endZoneCode")) Then
           
            'flag that this PickZone Configuration has changed
            Me.cboPickZoneName.ItemData(Me.cboPickZoneName.ListIndex) = 1
           
            lngZoneNumb = rsZoneConfig.fields("ZoneNumber") + 1
            rowZoneRow = Me.grdZoneConfig.Row
            strZoneCode = Trim(rsZoneConfig.fields("endZoneCode"))
            strZoneLoc = Trim(rsZoneConfig.fields("endZoneLoc"))
           
            rsZoneConfig.MoveNext
            If Not rsZoneConfig.EOF Then
                rsZoneConfig.fields("ZoneNumber") = rsZoneConfig.fields("ZoneNumber") + 1
            End If
           
            With rsZoneConfig
                .AddNew
                .fields("ZoneNumber") = lngZoneNumb
                .fields("EndZoneCode") = strZoneCode
                .fields("EndZoneLoc") = strZoneLoc
                .fields("fo_building") = Me.cboBuilding.ItemData(Me.cboBuilding.ListIndex)
                .fields("fo_rackType") = Me.cboRackType.ItemData(Me.cboRackType.ListIndex)
                .fields("ZoneName") = Trim(Me.cboPickZoneName.Text)
                .fields("ZoneQty") = 0
                .fields("PacksNeeded") = 0
                .fields("UnitsNeeded") = 0
            End With
           
            'reset the Zone numbers
            rsZoneConfig.MoveNext
            Dim icount As Long
            icount = lngZoneNumb + 1
            While Not rsZoneConfig.EOF
                rsZoneConfig.fields("ZoneNumber") = icount
                rsZoneConfig.MoveNext
                icount = icount + 1
            Wend
   
            rsZoneConfig.Sort = "ZoneName, fo_building, fo_rackType, ZoneNumber"
           
            Me.grdZoneConfig.Refresh
           
            Me.grdZoneConfig.Row = rowZoneRow + 1
            Call grdZoneConfig_ButtonClick(1)
        Else
            MsgBox "You can not insert a Zone Here", vbExclamation, "Pick Zone Configuration"
        End If
    End If
End Sub
0
Comment
Question by:tesla764
3 Comments
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 100 total points
ID: 39908530
Is there a field with that name ?  (Check for a misspelling)
What is the value of Me.cboRackType.ListIndex ?  (Maybe nothing is selected and it is -1)
0
 
LVL 27

Accepted Solution

by:
Ark earned 400 total points
ID: 39908537
It's probably due to not initialized Me.cboRackType - initially ListIndex=-1
try
If Me.cboRackType.ListIndex>-1 Then
    .fields("fo_rackType") = Me.cboRackType.ItemData(Me.cboRackType.ListIndex)
Else
 .fields("fo_rackType") = defaultRackType
End If

Open in new window

0
 

Author Comment

by:tesla764
ID: 39913619
Sorry I haven't responded just yet. I will soon. I have been working on other problems that have arisen.
Thanks for you patience.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Mobile 6.5 device Apache Flex 3 44
Create an excel spreadsheet that reads and inserts data 5 57
Problem to DocumentFormat 8 76
Authentication of Web Services 3 54
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

26 Experts available now in Live!

Get 1:1 Help Now