Ensuring a Form is Activated

hicksi

Board Regular
Joined
Mar 5, 2012
Messages
214
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I have an Excel sheet that is (mostly) controlled through UserForms.
There is one particular UserForm that is often NOT set active during the processes.
Ie, the AutoExec goes through a number of procedures to create a backup, purge backup copies, validate (and correct and sort) the data, and then show the first UserForm.
Mostly, the first field on the UserForm is activated, AND the form itself is active, so the user can enter data.
But sometimes, while the form appears to be active, the title is greyed and keying data doesn't show data in the field (ie, the "active" piece of the PC is somewhere else. If the user clicks on the form, all is well.
But what I NEED to do is ensure that the form is truly the active form so the user doesn't start keying data into the nowhere-land.

Is there a DoEvents or some command that will ensure that the cursor is IN that particular form?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi hicksi. It depend on whether you're hiding the form when not in use. If you are, then put this in the Userform activation code. Otherwise the initialize code might be best. Change the Userform name and control name to suit. HTH. Dave
VBA Code:
Dim T As Double
T = Timer
Do Until Timer - T > 1
  DoEvents
Loop
UserForm1.TextBox1.SetFocus
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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