Home > Blockchain >  Type mismatch when list box is empty
Type mismatch when list box is empty

Time:05-21

I have some code which works perfectly in submitting the contents of three list boxes that are within a form when they contain data, however when the list boxes are empty I am presented with a type mismatch error.

For i = LBound(Me.PartNoList.List) To UBound(Me.PartNoList.List)
        parts = parts & IIf(parts = "", "", vbNewLine) & Me.PartNoList.List(i, 0)
            Next

              With Sheets("Sales Order Log").Range("Sales_Data_Start")
                .Offset(TargetRow, 1).Value = SalesOrderNo
                    ' (...)
                        .Offset(TargetRow, 5).Value = parts
                            End With

    For i = LBound(Me.PartDescList.List) To UBound(Me.PartDescList.List)
        descparts = descparts & IIf(descparts = "", "", vbNewLine) & Me.PartDescList.List(i, 0)
                Next

                With Sheets("Sales Order Log").Range("Sales_Data_Start")
                    .Offset(TargetRow, 1).Value = SalesOrderNo
                        ' (...)
                            .Offset(TargetRow, 6).Value = descparts
                                End With

    For i = LBound(Me.PartQntList.List) To UBound(Me.PartQntList.List)
        qntparts = qntparts & IIf(qntparts = "", "", vbNewLine) & Me.PartQntList.List(i, 0)
            Next

                With Sheets("Sales Order Log").Range("Sales_Data_Start")
                    .Offset(TargetRow, 1).Value = SalesOrderNo
                        ' (...)
                            .Offset(TargetRow, 7).Value = qntparts
                                End With

Any help in diagnosing why this is happening would be very much appreciated.

CodePudding user response:

You need to check to see if each list box is empty before referencing the content e.g.

If Me.PartNoList.ListIndex <> -1 Then

Pressing End in the error message is stopping the rest of the code from running, so something else is happening to publish that data, or it's left over from a previous run

  • Related