-
Couldn't load subscription status.
- Fork 315
Description
I have a UserForm with a CommandButton CommandButton1, that is shown in Object Browser as being declared in my UserForm as WithEvents CommandButton1 As CommandButton but VBA has extended all of the Control members to the instance, so usages of CommandButton1 or Me.CommandButton1 give you access to all of the CommandButton members and all of the Control Members. Eg. Control's Height and _GetHeight members are both available.
But when declaring a variable cbCommandButton of type CommandButton and assigning it a reference to CommandButton1, all of the CommmandButton members are available but only some of the Control members are extended to the instance. Eg. Height is available, but _GetHeight is not.
It 's like VBA/MSForms knows that CommandButton1 is a CommandButton declaration hosted on a form (and therefore is and can be used as a complete Control), and that cbCommandButton is a CommandButton declaration in VBA code, and therefore is only a "partial" Control.
The code below shows various ways of obtaining a reference to the CommandButton1 instance, and then trying to invoke various Control members.
Dim tempHeight As Long
tempHeight = 847
CommandButton1.[_SetHeight] tempHeight
CommandButton1.[_GetHeight] tempHeight
tempHeight = CommandButton1.Height
CommandButton1.Height = tempHeight
Me.CommandButton1.[_SetHeight] tempHeight
Me.CommandButton1.[_GetHeight] tempHeight
tempHeight = Me.CommandButton1.Height
Me.CommandButton1.Height = tempHeight
Dim cbControl As MSForms.Control
Set cbControl = Me.Controls("CommandButton1")
cbControl.[_SetHeight] tempHeight
cbControl.[_GetHeight] tempHeight
tempHeight = cbControl.Height
cbControl.Height = tempHeight
With Me.CommandButton1
.[_SetHeight] tempHeight
.[_GetHeight] tempHeight
.Height = tempHeight
tempHeight = .Height
End With
Dim cbCommandButton As MSForms.CommandButton
Set cbCommandButton = Me.CommandButton1
cbCommandButton.[_SetHeight] tempHeight 'Error 438 - Object doesn't support this property or method
cbCommandButton.[_GetHeight] tempHeight 'Error 438 - Object doesn't support this property or method
tempHeight = cbCommandButton.Height
cbCommandButton.Height = tempHeight
Set cbCommandButton = Me.Controls("CommandButton1")
'Next line Fails
cbCommandButton.[_SetHeight] tempHeight 'Error 438 - Object doesn't support this property or method
cbCommandButton.[_GetHeight] tempHeight 'Error 438 - Object doesn't support this property or method
tempHeight = cbCommandButton.Height
cbCommandButton.Height = tempHeight
Dim obj As Object
Set obj = Me.Controls("CommandButton1")
obj.[_SetHeight] tempHeight 'Error 438 - Object doesn't support this property or method
obj.[_GetHeight] tempHeight 'Error 438 - Object doesn't support this property or method
tempHeight = obj.Height
obj.Height = tempHeight
With Me.Controls("CommandButton1")
.[_SetHeight] tempHeight 'Error 438 - Object doesn't support this property or method
.[_GetHeight] tempHeight 'Error 438 - Object doesn't support this property or method
.Height = tempHeight
tempHeight = .Height
End WithIs RD currently capable of extending all Control members to DeclarationType.Control members, and only some Control members to VBA declarations involving specific control types?
Will RD be able to resolve Control members according to the variable being used?