M. Daly
M. Daly

Reputation: 45

VBA Type Mismatch error with Join function

I'm running into a type mismatch error with the last line. Any ideas?

Dim language As String

Dim langOps(0 To 2) As String

If CheckBox10.Value = True Then
    langOps(0) = CheckBox10.Caption
End If

If CheckBox15.Value = True Then
    langOps(1) = CheckBox15.Caption
End If

If CheckBox29.Value = True Then
    langOps(2) = CheckBox29.Caption
End If

language = Join(langOps, [, ])

Upvotes: 2

Views: 790

Answers (2)

Elbert Villarreal
Elbert Villarreal

Reputation: 1716

Fails because you use square brackets >>[]<< instead quotes "".

language = Join(langOps, [, ]) >>> Wrong

language = Join(langOps, ", ") >>> Right

Upvotes: 1

Alex K.
Alex K.

Reputation: 175926

"" not []

language = Join(langOps, ", ")

([] is the evaluate shorthand syntax and [,] evaluates to an error which cannot be coerced to the string join wants hence the error)

Upvotes: 1

Related Questions