I'm currently testing some code for document automation on multi-user environment. For one specific machine there is a error 13 mismatch, where on other the code runs perfectly.
All machines have been installed with the same office version (365); all machines have been updated to the latest version.
Option Explicit
Private Sub butAddComponent_Click()
If txbCategory.Value = "" Then
MsgBox ("Category is required to fill in.")
Exit Sub
End If
Dim compList(2) As String
compList(0) = StrConv(txbCategory.Value, vbProperCase)
compList(1) = StrConv(txbComponent.Value, vbProperCase)
compList(2) = StrConv(txbType.Value, vbProperCase)
'Add entry to array
General.productsList = AddEntryToArray(General.productsList, compList)
'Select category
Call ufSupplier.RefillListboxes
End Sub
Function FillListBox(lstbx As MSForms.ListBox, arr As Variant)
If UBound(arr) = 0 And IsEmpty(arr(0)) Then Exit Function
Dim i As Long
For i = 0 To UBound(arr)
Select Case lstbx.name
Case "listType"
If UCase(listCategory.List(listCategory.ListIndex)) = UCase(arr(i)(0)) Then
If UCase(listComponent.List(listComponent.ListIndex)) = UCase(arr(i)(1)) Then
If Not IsItemInListbox(lstbx, CStr(arr(i)(2))) Then lstbx.AddItem arr(i)(2)
End If
End If
Case "listComponent"
If UCase(listCategory.List(listCategory.ListIndex)) = UCase(arr(i)(0)) Then
If Not UCase(IsItemInListbox(lstbx, CStr(arr(i)(1)))) Then lstbx.AddItem arr(i)(1)
End If
Case "listCategory"
If Not IsItemInListbox(lstbx, CStr(arr(i)(0))) Then lstbx.AddItem arr(i)(0)
End Select
Next i
End Function
Function IsItemInListbox(lstbx As MSForms.ListBox, str As String) As Boolean
IsItemInListbox = False
Dim i As Long
For i = 0 To lstbx.ListCount - 1
If UCase(str) = UCase(lstbx.List(i)) Then
IsItemInListbox = True
Exit Function
End If
Next i
End Function
When I run the code step by step the following happens:
First iteration:
lstbx.name = "listType"
IsItemInListbox gets called and is set to true
Second iteration
lstbx.name = "listComponent"
IsItemInListbox gets called and is set to true and I get a type 13 mismatch error when the code steps out of the IsItemInListbox.
I can bodge it by using an "On Error Resume Next", however I'm not sure that's the best way to go about it. It's one specific machine that outputs this error, the other machines don't have this. Does anyone know what could be the problem?
Bookmarks