ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can't assign a textbox to object (https://www.excelbanter.com/excel-programming/318581-cant-assign-textbox-object.html)

colin..

Can't assign a textbox to object
 
Running vb6 in xl2000.

I can't assign a textbox to a textbox object. Why not?

Assume that TextBox1 and CommandButton1 are defined on some form, or
worksheet, then this works:

Dim cb As CommandButton
Set cb = CommandButton1

But this fails with a type mismatch:

Dim tb As TextBox
Set tb = TextBox1

I seems that TextBox1 does not refer to the TextBox as a whole, but to the
text that it contains, i.e. TextBox1.Text.



Bob Umlas[_3_]

Can't assign a textbox to object
 
try (untested)
Set tb=Me.controls("Textbox1")

Bob Umlas
Excel MVP

"colin.." wrote in message
...
Running vb6 in xl2000.

I can't assign a textbox to a textbox object. Why not?

Assume that TextBox1 and CommandButton1 are defined on some form, or
worksheet, then this works:

Dim cb As CommandButton
Set cb = CommandButton1

But this fails with a type mismatch:

Dim tb As TextBox
Set tb = TextBox1

I seems that TextBox1 does not refer to the TextBox as a whole, but to the
text that it contains, i.e. TextBox1.Text.





colin..

Can't assign a textbox to object
 
Bob,
This still gives a type mismatch.
colin..


"Bob Umlas" wrote:

try (untested)
Set tb=Me.controls("Textbox1")

Bob Umlas
Excel MVP

"colin.." wrote in message
...
Running vb6 in xl2000.

I can't assign a textbox to a textbox object. Why not?

Assume that TextBox1 and CommandButton1 are defined on some form, or
worksheet, then this works:

Dim cb As CommandButton
Set cb = CommandButton1

But this fails with a type mismatch:

Dim tb As TextBox
Set tb = TextBox1

I seems that TextBox1 does not refer to the TextBox as a whole, but to the
text that it contains, i.e. TextBox1.Text.






Dave Peterson[_5_]

Can't assign a textbox to object
 
There's a textbox in the Drawing toolbar, too.

You'll want to be specific about which type you want to use:

Dim tb As msforms.TextBox

there's only one commandbutton, but this wouldn't hurt:
dim cb as msforms.commandbutton

And might remind you why you did things that way.

colin.. wrote:

Running vb6 in xl2000.

I can't assign a textbox to a textbox object. Why not?

Assume that TextBox1 and CommandButton1 are defined on some form, or
worksheet, then this works:

Dim cb As CommandButton
Set cb = CommandButton1

But this fails with a type mismatch:

Dim tb As TextBox
Set tb = TextBox1

I seems that TextBox1 does not refer to the TextBox as a whole, but to the
text that it contains, i.e. TextBox1.Text.


--

Dave Peterson

colin..

Can't assign a textbox to object
 
Dave,
Many thanks -- that's solved it.
colin..

"Dave Peterson" wrote:

There's a textbox in the Drawing toolbar, too.

You'll want to be specific about which type you want to use:

Dim tb As msforms.TextBox

there's only one commandbutton, but this wouldn't hurt:
dim cb as msforms.commandbutton

And might remind you why you did things that way.

colin.. wrote:

Running vb6 in xl2000.

I can't assign a textbox to a textbox object. Why not?

Assume that TextBox1 and CommandButton1 are defined on some form, or
worksheet, then this works:

Dim cb As CommandButton
Set cb = CommandButton1

But this fails with a type mismatch:

Dim tb As TextBox
Set tb = TextBox1

I seems that TextBox1 does not refer to the TextBox as a whole, but to the
text that it contains, i.e. TextBox1.Text.


--

Dave Peterson



All times are GMT +1. The time now is 03:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com