View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Daniel Bonallack Daniel Bonallack is offline
external usenet poster
 
Posts: 110
Default Which combobox has the focus?

Hi Dave

No, it's to be able to populate a combobox on the new form, depending on
which combobox had the focus in the first form.

So I'll try the code you've provided - thanks for that.

Daniel

"Dave Peterson" wrote:

Are you doing this to be able to return to the same control when you reshow the
first userform?

In my simple testing, that wasn't necessary. The activecontrol didn't change.

But you could get the activecontrol (or the activecontrol name) with something
like:

Option Explicit
Private Sub Label1_Click()

Dim ActCtrl As Control

Set ActCtrl = Me.ActiveControl

Me.Hide
UserForm2.Show
ActCtrl.SetFocus
Me.Show

End Sub

Or you could use its name:

Option Explicit
Private Sub Label1_Click()

Dim ActCtrlName As String

ActCtrlName = Me.ActiveControl.Name

Me.Hide
UserForm2.Show
Me.Controls(ActCtrlName).SetFocus
Me.Show

End Sub


Daniel Bonallack wrote:

I have a label on Userform A - if you click it, it opens up Userform B

Is there a way of capturing (when I click the label) which combobox had the
focus in UserForm A?

In other words, cmbIndustry in UserForm A has the cursor flashing in it.
Then I click Label A. I would like my variable sHadFocus to be equal to
"cmbIndustry".

Is that possible?

Thanks in advance
Daniel


--

Dave Peterson