Skip to Content
Former Member
Jul 16, 2007 at 08:52 PM

Object Enumerations - Casting 'Current'


I cannot figure out why I receive the error "Specified Cast is not valid." The offending line is marked.

Dim VV_Enum As IEnumerator
Dim oVV As SAPbobsCOM.IValidValue
oCB = oForm.Items.Item("CommGrp").Specific
VV_Enum = oCB.ValidValues.GetEnumerator
While VV_Enum.MoveNext
    oVV = VV_Enum.Current           <<< ERROR HERE
    If oVV.Value = oRS.Fields.Item(3).Value Then
        oCB.Select(oRS.Fields.Item(3).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
    End If
End While

If VV_Enum.Current Is Nothing Then
    oApplication.SetStatusBarMessage("The Commission Group '" & oRS.Fields.Item(4).Value & "' is no longer active.  You must save it to an active commission group.", SAPbouiCOM.BoMessageTime.bmt_Medium, True)
End If

I have tried defining oVV as an SAPbobsCOM.ValidValue. As well, I've tried explicit casting using CType(). No luck. I am simply trying to run through the list of values in a drop down object to see if a particular value (which is saved in a recordset from a previous SQL query) matches any of these values.

Thank you for your assistance in advance!