0

It seems that there are already some answers available but I can't find proper answer for my question.

Here is the code:

Private Sub Combo2_click()
Dim item_id, price As Integer
Dim item_name As String
If Combo2.Index Is 0 Then
    price = 30
ElseIf Combo2.Index Is 1 Then
    price = 40
ElseIf Combo2.Index Is 2 Then
    price = 50
ElseIf Combo2.Index Is 3 Then
    price = 60
Else
    price = 55
End If
End Sub

I am getting error as "Compile Error : Type MisMatch" ... I don't know why! It is showing error on the like Private Sub COmbo2_click() ...

1 Answer 1

5

There are two mistakes in your code:

1- You should use Combo2.ListIndex instead of .Index. (because index is used for something else and that's when your control is an element in an array)

2- You should replace Is with = (and that's what throws the exception of Type mismatch).

Hope that helps :)

Sign up to request clarification or add additional context in comments.

4 Comments

Additional info for point 2 "Is" is used in "Select Case" not If. That was so cryptic :)
@Jules the operator Is isn't restricted to use in Select Case only, it's used to compare between two objects, and yes it can be used in If statement (when comparing a pair of objects).
Yes you are right. I was going to add you can use is to compare object with nothing, but my comment was cryptic enough.
Another note - Dim a, b As Integer declares a as variant.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.