Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Which combobox has the focus?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Which combobox has the focus?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Which combobox has the focus?

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   Report Post  
Posted to microsoft.public.excel.programming
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

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

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Which combobox has the focus?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Focus after combobox Ed Excel Programming 4 September 27th 05 01:48 PM
OLE Combobox: Excel breaks down when it has focus [email protected] Excel Programming 5 January 29th 05 10:02 PM
How Do I Load A ComboBox RowSource From The Results Of Another ComboBox Minitman[_4_] Excel Programming 3 October 26th 04 07:58 PM
ComboBox and Set Focus Ming Shao[_2_] Excel Programming 1 April 28th 04 06:55 PM
Focus on combobox atkscott Excel Programming 4 November 20th 03 12:36 AM


All times are GMT +1. The time now is 04:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"