Type Mismatch Error Populating Label

  • Thread starter Thread starter ssjody
  • Start date Start date
S

ssjody

Rookie Here! This Code gives me a Type Mismatch Error if I try and Type
any Value in my Combo Box but if I Pick a choice from the Drop Down it
works fine. What am I doing wrong?

Jody

Private Sub cboCmPrimaryModel_Change()
Dim wo As Range
Set wo = Worksheets("PrimaryToOrionMakeCode").Range("A1:B3")
If Me.cboCmPrimaryModel.Value > "" Then
Label4.Caption = Application.VLookup(cboCmPrimaryModel.Value, wo, 2,
False)
End If
End Sub
 
Make the Style property of the combobox fmDropDownList
iso fmDropDownCombo.

This prevents entering non-existing text.


as is:
during typing in the combo box the change event is fired..
with every character you type.. the vlookup is executed on partial text.

if the vlookup cannot find the item it returns a variant of type Error
which cannot be assigned to the Caption.
Wrap the Vlookup in cStr() to prevent the runtime error.


Small example:
Sub foo()
Dim v, s$
'Put an error in the variant
v = [=na()]
'Put it in a string w/o error
s = CStr([=na()])
'This will give err 13, Type Mismatch
s = [=na()]

End Sub








--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


ssjody wrote :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top