Tim
Tim

Reputation: 206

vba how to check a double column combo for a value

I have a double column combo and I use the value in column(1) as my answer but when I want to check if that combo has a value using this code it does not execute so when I try to retrieve the value from a combo I get run time error 381. here is my code

 If Trim(CmBCodes.Value) = "" Then
    MsgBox "Please fill in the journey Code"
    CmBCodes.SetFocus
    Exit Sub
    End If

and changed that to this

   If Trim(CmBCodes.Value) = Null And Len(CmBCodes.Value)) = Null Then
    MsgBox "Please fill in the journey Code"
    CmBCodes.SetFocus
    Exit Sub
    End If

and still this code does not execute even if the combo has no value selected so it goes all the way to the piece of code where I try to retrieve the value and throws an error 381 here

  ws.Cells(iRow, 2).Value = UCase(CmBCodes.Column(1))

Upvotes: 0

Views: 35

Answers (1)

Harassed Dad
Harassed Dad

Reputation: 4704

If no selection has been made then combo and list boxes have a listindex of -1

If CmBCodes.ListIndex = -1  Then
    MsgBox "Please fill in the journey Code"
    CmBCodes.SetFocus
    Exit Sub
End If

Upvotes: 2

Related Questions