SetFocus Property

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
I have the following code which upon enablement is supposed to show an image file. There are about 8 different images, all set to invisible and on top of one another - so if you click the first radio button, the corresponding first image shows up. Clicking the second button brings up the second, and so on.

The problem is, when all are enabled I can't get the most recently selected to the top of the pile so it's visible. I tried the .setfocus command but it gives me an error that the control is either invisible, not enabled or not a control type that can accept the .setfocus.

Any suggestions?

Code:
Sub StaplingUpperLeft()
    If UserForm1.optStaplePortrait.Value = True Then
        UserForm1.imgtest1.Visible = True
        UserForm1.imgtest1.SetFocus
    End If
    If UserForm1.optStapleLandscape.Value = True Then
        UserForm1.imgtest2.Visible = True
        UserForm1.imgtest2.SetFocus
    End If
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
It appears you are using optionbuttons in which case only one should be visible at a time. If that is not the case for some reason, then I think you need to alter the z order of the controls.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,248
Members
452,900
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top