Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Daniel,
Try something like this ' In Userform1 Dim mCtrInFocus As Control Public Property Set propHadFocus(ctr As Control) Set mCtrInFocus = ctr End Property Public Property Get propHadFocus() As Control Set propHadFocus = mCtrInFocus End Property Private Sub ComboBox1_Enter() Set propHadFocus = ComboBox1 End Sub ' in Userform2 with Userform1 loaded Private Sub CommandButton1_Click() Dim ctl As Control On Error Resume Next Set ctl = UserForm1.propHadFocus If Not ctl Is Nothing Then MsgBox ctl.Name, , TypeName(ctl) Else MsgBox "can't get control" End If End Sub Regards, Peter T "Daniel Bonallack" wrote in message ... 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Peter
Thanks very much, I'll give this a go. regards Daniel "Peter T" wrote: Hi Daniel, Try something like this ' In Userform1 Dim mCtrInFocus As Control Public Property Set propHadFocus(ctr As Control) Set mCtrInFocus = ctr End Property Public Property Get propHadFocus() As Control Set propHadFocus = mCtrInFocus End Property Private Sub ComboBox1_Enter() Set propHadFocus = ComboBox1 End Sub ' in Userform2 with Userform1 loaded Private Sub CommandButton1_Click() Dim ctl As Control On Error Resume Next Set ctl = UserForm1.propHadFocus If Not ctl Is Nothing Then MsgBox ctl.Name, , TypeName(ctl) Else MsgBox "can't get control" End If End Sub Regards, Peter T "Daniel Bonallack" wrote in message ... 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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks very much - your solution worked perfectly
"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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Focus after combobox | Excel Programming | |||
OLE Combobox: Excel breaks down when it has focus | Excel Programming | |||
How Do I Load A ComboBox RowSource From The Results Of Another ComboBox | Excel Programming | |||
ComboBox and Set Focus | Excel Programming | |||
Focus on combobox | Excel Programming |