Johnson Jason
Johnson Jason

Reputation: 721

VBA - (Excel) Why can't I set Textbox type for Userform without getting a type mismatch error?

I have a Userform and this is the code for my control button. Trying to pass a Textbox to a function using the following code

Private Sub pdclear_Click()
Dim textinput As TextBox
Set textinput = frmBigInputBox
Call clear(textinput)
End Sub

The line highlighted yellow in debug mode is

Set textinput = frmBigInputBox

Why does this cause a "13 type mismatch" error??? What am I doing wrongly?

Upvotes: 3

Views: 1979

Answers (2)

Roland
Roland

Reputation: 976

I could reproduce the error and found this: http://forums.devx.com/showthread.php?168758-Excel-VBA-Using-TypeOf

So you will have to define it as MSForms.TextBox, it seems.

Upvotes: 3

vacip
vacip

Reputation: 5416

Try using MSForms.TextBox. As in

Dim textinput As MSForms.TextBox

Works for me.

Upvotes: 5

Related Questions