Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Set focus on controls of modeless form

When I initially load my modeless form, the input focus
usually begins on my first textbox control (or any other
control).

However, if you click on the spreadsheet, then click
back to the modeless control, the input focus is lost
(ie. not set on any control). How can I set the
input focus back on Textbox1 if someone clicks on
the spreadsheet and then clicks back to the modeless form???

I already tried the following code, but it doesnt work:

Private Sub UserForm_Activate()
UserForm1.TextBox1.SetFocus
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Set focus on controls of modeless form

Hi Robert,

I don't know why the following works. I suspect some kind of bug but use the
userform click event and then set the focus to another control first then to
the one you really want.

Private Sub UserForm_Click()
Me.TextBox2.SetFocus
Me.TextBox1.SetFocus
End Sub

--
Regards,

OssieMac

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Set focus on controls of modeless form

Hi OssieMac,

The code below works, but it assumes that the user will click somewhere
WITHIN the userform. If the user clicks on the top title bar to
re-activate the userform that code will not work.

How can I detect if the form is activated by a click on the top title
bar??


"OssieMac" wrote in message
...
Hi Robert,

I don't know why the following works. I suspect some kind of bug but use
the
userform click event and then set the focus to another control first then
to
the one you really want.

Private Sub UserForm_Click()
Me.TextBox2.SetFocus
Me.TextBox1.SetFocus
End Sub

--
Regards,

OssieMac


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Set focus on controls of modeless form

I don't know the answer to that one Robert. I think that Excel is missing
something here and it should work.

--
Regards,

OssieMac


"Robert Crandal" wrote:

Hi OssieMac,

The code below works, but it assumes that the user will click somewhere
WITHIN the userform. If the user clicks on the top title bar to
re-activate the userform that code will not work.

How can I detect if the form is activated by a click on the top title
bar??


"OssieMac" wrote in message
...
Hi Robert,

I don't know why the following works. I suspect some kind of bug but use
the
userform click event and then set the focus to another control first then
to
the one you really want.

Private Sub UserForm_Click()
Me.TextBox2.SetFocus
Me.TextBox1.SetFocus
End Sub

--
Regards,

OssieMac


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Set focus on controls of modeless form

Userforms do not expose a 'GotFocus' event, which is not the same as the
Userform's VBA Activate event.

Simplest approach would be with an OntIme macro to check which window is
currently active, which you can get with the GetForegroundWindow API.

If you need to know more accurately when user activates Excel or Userform,
or some other window (actually just beforehand), a low level hook along the
lines of the 'CBTProc Function' as demonstrated to you in one of your other
threads would keep you informed. Overkill I would have thought though for
this objective alone.

Regards,
Peter T


"Robert Crandal" wrote in message
...
Hi OssieMac,

The code below works, but it assumes that the user will click somewhere
WITHIN the userform. If the user clicks on the top title bar to
re-activate the userform that code will not work.

How can I detect if the form is activated by a click on the top title
bar??


"OssieMac" wrote in message
...
Hi Robert,

I don't know why the following works. I suspect some kind of bug but use
the
userform click event and then set the focus to another control first then
to
the one you really want.

Private Sub UserForm_Click()
Me.TextBox2.SetFocus
Me.TextBox1.SetFocus
End Sub

--
Regards,

OssieMac




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
Modeless form keeps taking 'focus' Michelle Excel Programming 5 June 14th 08 07:09 PM
Focus In Modeless Form (spare me the grief) ThinkImInTrouble Excel Programming 2 July 10th 05 06:21 PM
How do I switch focus from a modeless user form back to the excel. Yoam69 Excel Programming 7 December 7th 04 08:26 PM
Modeless User Form and Worksheet Focus JWolf Excel Programming 2 May 26th 04 08:27 PM
Removing focus from a Modeless Form? Ian Chappel Excel Programming 2 May 1st 04 07:54 PM


All times are GMT +1. The time now is 07:17 PM.

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

About Us

"It's about Microsoft Excel"